2020 10th C/C++ Group B Second Blue Bridge Cup Provincial Competition Zhenti

Here is the topic column of the Blue Bridge Cup over the years. It will be updated successively and the real questions and answers of previous years will be released. I welcome you to follow me. Your likes and attention are the best motivation for me! ! !
The real questions are updated every day, so stay tuned

Blue Bridge Cup real questions and detailed answers over the years


Question 1: Making the Door Sign

Topic Description
Xiao Lan wants to make house numbers for the residents of a street. There are a total of 2020 residents in this street, and the house numbers are numbered from 1 to 2020. The method of Xiaolan to make the house number is to first make the number characters from 0 to 9, and finally paste the characters on the house number as needed. For example, the house number 1017 needs to paste the characters 1, 0, 1, and 7 in sequence, that is, one character 0 is required. 2 characters 1, 1 character 7. How many characters 2 are needed in total to make all the house numbers 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: Estimated Fractions

Problem 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, 7/1 are all reduced fractions. Excuse me, how many reduced fractions are there, and both the numerator and denominator are integers between 1 and 2020 (including 1 and 2020)
topic analysis Violent search, judge the topic 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 Filling in Numbers

Description of the topic
As shown in the figure below, Xiao Ming fills an infinite matrix with a positive integer "snake" 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 count the number in the 20th row and 20th column of the matrix?

1 2 6 7 153 5 8 144 9 1310 1211

Topic analysis
The graph can be rotated 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

Question 4: Running Exercise

Topic description
Xiaolan exercises every day. Under normal circumstances, Xiaolan runs 1 km a day. If a certain day is Monday or the beginning of the month (1st), in order to motivate himself, Xiaolan has to run 2 kilometers. If it is Monday or the beginning of the month at the same time, Xiaolan also runs 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 in total during this time?
Problem analysis
First calculate the total number of days and months, and then find out how many Mondays there are in total, and the number of days in the month on Mondays The
final total number of days + the number of days in the week + the number of days at the beginning of the month - the number of days that overlap with the beginning of the
month

#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 type of text.
Seven-segment code The figure above shows an illustration of the seven-segment code 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 has to choose a part of the diodes (at least one) to emit light to express the characters. When designing the expression of the characters, all the light-emitting diodes are required to be connected together.
For example: b emits light, other diodes do not emit light can be used to express a character.
For example: c emits light, other diodes do not emit light 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 illuminated, f, g not illuminated can be used to express a character.
For example: b, f emit light, other diodes do not emit light and cannot be used to express a character, because the light emitting diodes are not connected together.
Excuse me, how many different characters can Xiaolan express with a seven-segment digital tube?
insert image description here

topic analysis
topic code



Question 6: Score Statistics

Item description
Xiaolan organized an exam for the students, with a total score of 100 points, and each student's score was an integer from 0 to 100. If the score is at least 60 points, it is called a pass. A score of at least 85 is considered excellent. Please calculate the pass rate and the excellent rate, expressed as a percentage, and the part before the percent 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 to be tested. The next n lines each contain an integer from 0 to 100 representing a student's score.
【Output format】 Two lines are output, each line is a percentage, which represent the pass rate and the excellent rate respectively. 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 code



Question 7: Date of Palindrome

Title Description
During the Spring Festival in 2020, there is a special date that caught everyone's attention: February 2, 2020. Because if this date is written in the format of "yyyymmdd" as an 8-digit number, it is 20200202, which happens to be a palindrome. We call such dates a palindrome date. Some people say that 20200202 is a special day "once in a thousand years". Xiao Ming disagrees with this very much, because less than 2 years later will be the next palindrome date: 20211202, which is December 2, 2021. Some people also said that 20200202 is not just a palindrome date, but a palindrome date of ABABABA type. Xiao Ming also disagrees with this, because in about 100 years, the next palindrome date of the ABABABA type will be encountered: 21211212, which is December 12, 2121. It's not "once in a thousand years", but at most "twice in a thousand years". Given an 8-digit date, please calculate which day is the next palindrome date and the next palindrome date of type ABABABA after the date.
【Input format】The
input contains an eight-digit integer N, which represents the date.
【Output format】
Output two lines, each line contains one eight-digit number. The first row represents the next palindrome date, and the second row represents the next palindrome date of type ABABABA.
[Sample input]
20200202
[Sample output]
20211202
21211212
[Evaluation case scale and convention]
For all evaluation use cases, 10000101 <= N <= 89991231, and ensure that N is an 8-digit representation of a valid date.
topic analysis
topic code



Question 8: Substring Score Sum

Problem Description
For a string S, we define the score f (S ) of S as the
number of distinct characters that appear in S. For example f("aba") = 2, f("abc") = 3, f("aaa") = 1.
Now given a string S[0::n − 1] (of length n), please calculate for all non-
empty substrings S[i::j](0 ≤ i ≤ j < n) of S, f What is the sum of (S[i::j]) .
【Input format】
Enter a line containing a string S consisting of lowercase letters.
【Output format】
Output an integer to represent the answer.
【Example input】
ababc
【Example output】
28
【Example 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 code



Question 9: Plane Segmentation

Problem Description
There are N straight lines on a plane, the ith straight line is y = Ai x+Bi
Please calculate these lines to divide the plane into several parts.
【Input format】
The first line of the input contains an integer N, 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 code



Question 10: String Sorting

Topic description
Xiaolan recently learned some sorting algorithms, among which bubble sort impressed him a lot.
In bubble sort, only two adjacent elements can be swapped at a time. Xiaolan found that if the characters in a string are sorted and only two adjacent characters are allowed to be swapped, the total number of swaps in bubble sort is the least among all possible sorting schemes.
For example, for string lan ordering, only 1 exchange is required. For string qiao sorting, a total of 4 swaps 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 the string and can't find it now.
Please help Xiaolan to find a string that contains only lowercase English letters and no repeated letters. Sorting the characters of this string requires exactly V exchanges. If it is possible to find more than one, please tell Xiaolan the shortest one. If there are still more than one shortest, please tell Xiaolan the one with the smallest lexicographical order. Note that strings can contain the same characters.
【Input format】
The first line of input contains an integer V, the lucky number of the little blue.
[Output format]
One line of string required by the question.
【Sample input】
4
【Sample output】
bbaa
【Sample input】
100
【Sample output】
jihgfeeddccbbaa

topic analysis

topic code



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324768727&siteId=291194637