2020 10th C/C++ Group B Second Blue Bridge Cup Provincial Match Real Questions

Here is the topic column of the Blue Bridge Cup over the years. It will be updated and will release the real questions and answers from previous years. Welcome friends to pay attention to me. Your likes and attention are the best motivation for me! ! !
Update one real question every day, so stay tuned

Lanqiao Cup Past Papers and Detailed Answers


Question 1: Making House Numbers

Title description
Xiaolan wants to make house numbers for residents in a street. There are a total of 2020 residents on this street, and the house numbers are numbered from 1 to 2020. The method for Xiaolan to make the house plate is to make the numeric characters from 0 to 9 first, and finally paste the characters on the house plate as needed. For example, house plate 1017 needs to paste the characters 1, 0, 1, 7 in sequence, that is, 1 character 0 is needed. 2 characters 1, 1 character 7. How many characters 2 are required to make all the number 1 to 2020?
Topic analysis
Violent search to determine whether the characters in each position meet the conditional
topic code

#include<iostream>
using namespace std;
int calu(int num)
{
    
    
	int ans = 0;
	while(num)
	{
    
    
		if(num%10==2)
			ans++;
		num/=10;
	}
	return ans;
}
int main()
{
    
    
	int cnt = 0;
	for(int i = 1; i <=2020; i++)
	{
    
    
		cnt+=calu(i);
	}
	cout << cnt <<endl;
	return 0;
} 

Question answer

624

Question 2: Restricted score

Title description
If the greatest common divisor of the numerator and denominator of a fraction is 1, the fraction is called a reduced fraction. For example, 3/4, 5/2, 1/8, and 7/1 are all reduced scores. Excuse me, how many reduced scores are there, the numerator and denominator are integers between 1 and 2020 (including 1 and 2020)
problem analysis
Violent search, judge the problem code by the greatest common divisor

#include<iostream>
using namespace std;

int gcd(int a,int b)
{
    
    
	if(a%b==0)
		return b;
	else
		return gcd(b,a%b);
}
int main()
{
    
    
	int ans = 0;
	for(int i = 1; i <= 2020; i++)
	{
    
    
		for(int j = 1; j <= 2020; j++)
		{
    
    
			if(gcd(i,j)==1)
			{
    
    
				ans++;
			}
		}
	}
	cout << ans <<endl;
	return 0;
}

Question answer
2481215

在这里插入代码片

Question 3: Serpentine fill in the number

Title description
As shown in the figure below, Xiaoming fills an infinite matrix with a "snake shape" of positive integers starting from 1. It is easy to see that the number in the second row and second column of the matrix is ​​5. Could you please calculate the number in the 20th row and 20th column of the matrix?

1 2 6 7 153 5 8 144 9 1310 1211

Problem analysis:
You can rotate the graph 45 degrees clockwise, we can find that 20 rows and 20 columns should be located in the middle of the 49th layer, and then the simulation can be calculated

111
	  	      3 2
224 5 6
	        10 9 8 7
3311 12 13 14 15
.................

Topic code

#include<iostream>

using namespace std;

int main()
{
    
    
	//首先计算第20行20列位于三角形第几行,用公式算出是2*20-1=39行
	//计算39行的最后一个数 
	int n = 20;
	n = n*2-1;
	int ans = 0,sum =  0;
	for(int i = 1; i <=n ;i++)
	{
    
    
		sum+=i; 
	} 
	ans = (sum+sum-n+1)/2;
	cout << ans <<endl;
	return 0;
	 
} 

Question answer

761

Fourth question: running exercise

Title description
Xiaolan exercises every day. Under normal circumstances, Xiaolan runs 1 kilometer a day. If a day is Monday or the beginning of the month (1st), in order to motivate himself, Xiaolan will run 2 kilometers. If it is also Monday or the beginning of the month, Xiaolan will also run 2 kilometers. Xiaolan has been running for a long time, from Saturday, January 1, 2000 (inclusive) to Thursday, October 1, 2020 (inclusive). How many kilometers did Xiaolan run during this period?
Topic analysis
first calculate the total number of days and number of months, and then find a number on Monday, and Monday is the number of days of the month a total
number + the number of weeks one day + early days of the last of days - Monday and early coincide with the number of days
subject codes

#include<iostream>

using namespace std;
int run(int year)
{
    
    
	return (year%400==0)||(year%4==0&&year%100!=0);
}
int main()
{
    
    
	int monNum = 0,weekNum = 0,monWeek = 0,days = 0,ans = 0;
	int monDay[13] = {
    
    0,31,30,31,30,31,30,31,31,30,31,30,31};
	for(int i = 2000; i <= 2020; i++)
	{
    
    
		//闰年处理 
		if(run(i)) 
			monDay[2] = 29;
		else 
			monDay[2] = 28;
		//计算总天数和月份 
		for(int j = 1; j <= 12; j++)
		{
    
    
			if(i==2020&&j==10) break;
			monNum += 1;
			days+=monDay[j];
			if((days+1)%7==3)
			{
    
    
				monWeek++;
			}
			
		}
	} 
	weekNum += days/7;
	if(days%7>=3) 
		weekNum++;
	//cout << days+1 << ends << weekNum <<ends << monNum+1 << ends << monWeek <<endl;
	ans = days+1 + weekNum +monNum+1 - monWeek;
	cout << ans <<endl;


	return 0;
}

Question answer

8879

Question 5: Seven-segment code

Title description
Xiaolan uses a seven-segment digital tube to represent a special kind of text.
Seven-segment code The figure above shows an icon of the seven-segment digital tube. There are 7 segments of light-emitting diodes in the digital tube, which are marked as a, b, c, d, e, f, g. Xiaolan chooses a part of the diode (at least one) to emit light to express characters. When designing the expression of characters, all light-emitting diodes are required to be connected in one piece.
For example: b is illuminated, other diodes do not emit light can be used to express a character.
For example: c light-emitting, other diodes not light-emitting can be used to express a character. This scheme and the scheme on the previous line can be used to represent different characters, although they look similar.
For example: a, b, c, d, e glow, f, g not glow can be used to express a character.
For example: b, f are luminous, other diodes are not luminous and cannot be used to express a character because the luminous diodes are not connected together.
Excuse me, how many different characters can Xiaolan express with a seven-segment digital tube?
Insert picture description here

Topic analysis
topic codes



Question 6: Performance Statistics

Topic description
Xiaolan organized an exam for the students. The total score is 100 points, and each student's score is an integer from 0 to 100. If the score is at least 60 points, it is called a pass. If the score is at least 85 points, it is called excellent. Please calculate the pass rate and the excellent rate, expressed as a percentage, and the part before the percentage sign is rounded to the nearest whole number.
[Input format] The first line of input contains an integer n, which represents the number of people in the exam. The next n lines, each line contains an integer from 0 to 100, representing a student's score.
[Output format] Output two lines, each line with a percentage, respectively representing the passing rate and the excellent rate. The part before the percent sign is rounded to the nearest whole number.
[Sample input]
7
80
92
56
74
88
100
0
[Sample output]
71%
43%

Topic analysis
topic codes



Question 7: Palindrome Date

The title describes that
during the 2020 Spring Festival, there is a special date that attracts everyone's attention: February 2, 2020. Because if this date is written as an 8-digit number in the format of "yyyymmdd", it is 20200202, which happens to be a palindrome number. We call such a date a palindrome date. Some people say that 20200202 is a special day of "one encounter in a thousand years". Xiaoming disagrees with this, because less than two years later is the next palindrome date: 20211202, which is December 2, 2021. Some people also said that 20200202 is not just a palindrome date, but an ABABBABA-type palindrome date. Xiaoming also disagrees with this, because about 100 years later, he will meet the next ABABBABA palindrome date: 21211212, which is December 12, 2121. It's not a "one encounter in a thousand years", but a "two encounters in a thousand years" at best. Given an 8-digit date, please calculate the next palindrome date and the next ABABBABA palindrome date after the date.
[Input Format] The
input contains an eight-digit integer N, which represents the date.
[Output format]
Output two lines, each line has an eight-digit number. The first line indicates the date of the next palindrome, and the second line indicates the date of the next ABABBABA palindrome.
[Sample input]
20200202
[Sample output]
20211202
21211212
[Evaluation use case scale and conventions]
For all evaluation use cases, 10000101 <= N <= 89991231, to ensure that N is an 8-digit representation of a legal date.
Topic analysis
topic codes



Question 8: Substring score sum

Title description
For a string S, we define the score f (S) of S as the
number of different characters in S. For example, f ("aba") = 2, f ("abc") = 3, f ("aaa") = 1.
Now given a string S [0 :: n - 1] ( of length n), is calculated for a non-empty you all the S
substring S [i :: j] (0 ≤ i ≤ j <n), f What is the sum of (S [i:: j])?
[Input Format]
Input a line containing a string S composed of lowercase letters.
[Output format]
Output an integer to represent the answer.
[Sample input]
ababc
[Sample output]
28
[Sample description]
Substring f value
a 1
ab 2
aba 2
abab 2
ababc 3
b 1
ba 2
bab 2
babc 3
a 1
ab 2
abc 3
b 1
bc 2
c 1

Topic analysis
topic codes



Question 9: Plane segmentation

Title Description
There are N straight lines on the plane, and the i-th straight line is y = Ai x+Bi.
Please calculate these straight lines to divide the plane into several parts.
[Input format]
The first line of input contains an integer N, and the following N lines contain two certificates Ai, Bi
[Output format] An integer represents the answer
[Sample input]
31
1
2 2
3 3
[Sample output]
6

Topic analysis
topic codes



Tenth question: String sorting

Title description
Xiaolan recently learned some sorting algorithms, among which bubble sorting impressed him.
In bubble sorting, only two adjacent elements can be exchanged at a time. Xiaolan found that if the characters in a string are sorted and only two adjacent characters are allowed to be exchanged, the total number of exchanges for bubble sorting is the least among all possible sorting schemes.
For example, for string lan sorting, only 1 exchange is required. For the string qiao sorting, a total of 4 exchanges are required.
Xiaolan found a lot of strings and tried to sort them. He happened to come across a string that needed V exchanges, but he forgot to write down this string, and he can't find it now.
Please help Xiaolan find a string that only contains lowercase English letters and no repetition of letters. Sorting the characters of this string requires exactly V exchanges. If you can find more than one, please tell Xiaolan the shortest one. If there are still multiple shortest ones, please tell Xiaolan the one with the smallest lexicographic order. Please note that the same characters can be included in the string.
[Input format]
The first line of input contains an integer V, a lucky number for Xiaolan.
[Output format]
A line of character string required by the title.
[Sample input]
4
[Sample output]
bbaa
[Sample input]
100
[Sample output]
jihgfeeddccbbaa

Topic analysis

Topic code



Guess you like

Origin blog.csdn.net/kiwi_berrys/article/details/111461536