C-language daily quizzes

Table of contents

[Lanqiao Cup 2015 Province A] Beverage Exchange

Question description

Input format

Output format

Input and output samples

# [Lanqiao Cup 2023 Province A] Square Difference

Question description

Input format

Output format

Input and output samples

Instructions/Tips

[Sample description]

  [NOIP2001 popularization group] calculation of numbers

Question description

Input format

Output format

Input and output samples

Instructions/Tips

Example 1 Explanation

Data size and conventions

 [NOIP2008 Improvement Group] Stupid Little Monkey

Question description

Input format

Output format

Input and output samples

Instructions/Tips


[Lanqiao Cup 2015 Province A] Beverage Exchange

Question description

Leyangyang Beverage Factory is holding a promotional event. LeYangYang C-type drink can be exchanged for another C-type drink with 3 bottle caps, and the cycle can continue (but temporary loans or credit are not allowed).

Please calculate, if Xiao Ming does not waste bottle caps and participates in activities as much as possible, then for the n bottles of drinks he initially bought, how many bottles of drinks can he drink in total in the end.

Input format

An integer n, representing the number of drinks to start purchasing. (0<n<10000)

Output format

An integer representing the actual number of drinks received.

Input and output samples

Enter #1

100

 Output #1

149

 Enter #2

101

Output #2

151
#include<stdio.h>
int main()
{
	int n = 0;
	int sum = 0, num = 0;//sum瓶盖数,num饮料数
	scanf("%d", &n);
	while (n)
	{
		n--;
		sum++;
		num++;
		if (sum == 3)
		{
			num++;  
			sum = 1;//换了一瓶饮料,就有一个盖子
		}
	}
	printf("%d", num);
	return 0;
}

# [Lanqiao Cup 2023 Province A] Square Difference

Question description

Given L, R, ask how many numbers x in L≤x≤R satisfy the existence of integers y,z such that x=y^2−z^2.

Input format

The input line contains two integers L and R, separated by a space.

Output format

Output a line containing an integer and the number of x that meets the conditions given in the question.

Input and output samples

Enter #1

1 5

Output #1

4

Instructions/Tips

[Sample description]
  • 1=1^2−0^2
  • 3=2^2−1^2
  • 4=2^2−0^2
  • 5=3^2−2^2
#include<stdio.h>
int JiShu(int n) {
	if (n % 4 == 0) {
		return 1;
	}
	else if (n % 2 != 0) {
		return 1;
	}
	return 0;
}
	//1.如果y+z为奇数:x就为奇数,  n^2-(n-1)^2 = 2*n+1;
	//2.如果y-z为偶数:x就为4的倍数,n^2-(n-2)^2 = 4*n;

int main() {
	int n, m, count = 0;
	scanf("%d%d", &n, &m);
	for (int i = n; i <= m; i++)
	{
		if (JiShu(i) == 1) 
		{
			count++;
		}
	}
	printf("%d", count);
}

  [NOIP2001 popularization group] calculation of numbers

 

Question description

Given a positive integer n, the sequence is required to be constructed as follows:

  1. A sequence with only one number n is a legal sequence.
  2. Add a positive integer to the end of a legal sequence, but the positive integer cannot exceed half of the last item in the sequence, and a new legal sequence can be obtained.

Please find out how many legal sequence there are in total. Two legal sequence a, b are different if and only if the lengths of the two sequences are different or there is a positive integer i≤|a∣, such that ai​ is not equal to bi​.

Input format

The input is only one integer on one line, representing n.

Output format

Output one integer per line, representing the legal number of sequences.

Input and output samples

Enter #1

6

Output #1

6

Instructions/Tips

Example 1 Explanation

The numbers that satisfy the condition are:

  • 6
  • 6,1
  • 6,2
  • 6,3
  • 6,2,1
  • 6,3,1

Data size and conventions

For all test points, it is guaranteed that 1≤n≤10^3.

#include<stdio.h>
int JiShu(int n,int* str)
{
	int count = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= i / 2; j++)
		{
			str[i] += str[j];     
			//str[1] = 1
			//str[2] = 2 = str[1]+1
			//str[3] = 2 = str[1]+1
			//str[4] = 4 = str[1]+str[2]+1
			//str[5] = 4 = str[1]+str[2]+1
			//str[6] = 6 = str[1]+str[2]+str[3]+1
/*
我们以6为例子来进行说明
6后面可以跟上1,2,3组成61,62,621,63,631
61,63后面跟不了,62可以跟上1组成621,63可以跟上1组成631
再加上6本身就可以得到6的种类
即61,62,621,63,631
也就是只要算出1,2,3的种类加上自身就可以得到6的种类
*/
		}
		str[i]++;//加上本身
	}
	count = str[n];
	return count;
}
int main()
{
	int n = 0;
	int str[1000] = { 0 };
	scanf("%d", &n);
	int rs = JiShu(n,str);
	printf("%d", rs);
	return 0;
}

 [NOIP2008 Improvement Group] Stupid Little Monkey

Question description

Stupid little monkey has a very small vocabulary, so he has a headache every time he takes multiple-choice English questions. But he found a method, and experiments have proven that when using this method to choose options, the probability of choosing the right one is very high!

The specific description of this method is as follows: Assume that maxn is the number of occurrences of the letter that appears most often in the word, and minn is the number of occurrences of the letter that appears the least frequently in the word. If maxn−minn is a prime number, then the stupid monkey thinks that this It's a Lucky Word, and such a word is probably the correct answer.

Input format

A word in which only lowercase letters may appear and whose length is less than 100 characters.

Output format

has two lines in total. The first line is a string. Assume that the input word is Lucky Word, then output Lucky Word, otherwise output No Answer;

The second line is an integer. If the input word is Lucky Word, the value of maxn−minnmaxn−minn is output, otherwise 0 is output.

Input and output samples

 Enter #1

error

Output #1

Lucky Word
2

 Enter #2

olympic

 Output #2

No Answer
0

Instructions/Tips

[Input and output sample 1 explanation]

The most frequent letter r in the word error appears 3 times, and the least frequent letter appears 1 time. 3−1=2, 2 is a prime number.

[Input and output sample 2 explanation]

The letter i that appears most often in the word olympic appears once, and the letter that appears least frequently appears once. 1−1=0, 0 is not a prime number.

#include<stdio.h>
#include<string.h>
int main()
{
	char str[100] = { 0 }, maxn = 0, minn = 100;
	const int ret[25] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
	//0-100的所有质数,加const修饰表示不可修改
	int arr[26] = { 0 };
	gets(str);
	int rs = strlen(str);
	for (int i = 0; i < rs; i++)
	{
		arr[str[i] - 'a']++;
		//记录各个字母出现的次数
		//arr[0]表示a,arr[1]表示b
	}
	for (int i = 0; i < 26; i++)
	{
		if (arr[i] > maxn)
		{
			maxn = arr[i];
		}
		if (arr[i] > 0 && arr[i] < minn)
		{
			minn = arr[i];
		}
	}
	for (int i = 0; i < 25; i++)
	{
 
		if ((maxn - minn) == ret[i])
		{
			printf("Lucky Word\n%d", maxn - minn);
			return 0;
		}
	}
	printf("No Answer\n0");
	return 0;
}

Guess you like

Origin blog.csdn.net/2301_79201049/article/details/134756140