[Blue Bridge Cup] Exam Questions Training-Analysis of the Exam Questions of the 6th Lanqiao Cup Provincial Competition C/C++ University Group B

Question 1 Number of Lottery Tickets 

Some people are very superstitious about numbers. For example, numbers with "4" think that they are homophonic with "death", which is unlucky.
Although these claims are pure nonsense, they sometimes have to cater to the needs of the public. The lottery number of a lottery is 5 digits (10000-99999), and the number with "4" is required. The organizer asks you to calculate how many lottery tickets can be issued if any two lottery tickets are not duplicated.
Please submit the number (an integer) and do not write any extra content or descriptive text.

Answer: 52488

Arrange, 8*9*9*9*9

 

Question 2 Galaxy Bomb

There are many X-star artificial "bombs" floating in the vast space of the X galaxy, which are used as road signs in the universe.
Each bomb can be set to explode in days.
For example, if the Alpha Bomb is placed on November 11, 2015, 2015, and the time is 15 1515 days, it will explode on November 16, 2015, 2015.
There is a beta bomb, which was placed on the 9th of November 9th, 2014, November 9th, 2014. The time is 1000 1000 1000 days. Please calculate the exact date of its explosion.
Please fill in the date in the format yyyy − mm − dd yyyy-mm-ddyyyy−mm−dd, which is 4 44-digit year 2 22-digit month 2 22-digit day. For example: 2015-02-19
Note: Please write in strict accordance with the format. No other words or symbols can appear.

Answer: 2017-8-5 

 

The third question

Observe the following addition formula:
Insert picture description here
Among them, the same Chinese character represents the same number, and different Chinese characters represent different numbers.
Please fill in the 4 digits represented by "Sanyang Xianrui" (the answer is unique), and do not fill in any redundant content.

Answer: 1085

Full arrangement

#include <iostream>
#include <algorithm>
using namespace std;
 
int main(int argc, char** argv) {
	int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
	do{
		if(a[0] == 0 || a[4] == 0){
			continue;
		}
		int num1, num2, sum;
		num1 = a[0]*1000 + a[1]*100 + a[2]*10 + a[3];
		num2 = a[4]*1000 + a[5]*100 + a[6]*10 + a[1];
		sum = a[4]*10000 + a[5]*1000 + a[2]*100 + a[1]*10 + a[7];
		if(num1 + num2 == sum){
			cout << num2 ;
			break;
		}
	}while(next_permutation(a, a+10));
	
	return 0;
}

 

Output in the fourth question grid

The StringInGrid function will print the specified string in a grid of a specified size.
The string is required to be centered in both the horizontal and vertical directions.
If the string is too long, it is truncated.
If it can't be centered, you can move it slightly to the left or up.
The following program implements this logic, please fill in the missing code in the underlined part.
For the data in the title, it should output:

Insert picture description here

Note: Only fill in the missing content, do not write any existing codes or explanatory text on the title.

 答案:(width - strlen(buf))/2 - 1, " ", buf, (width - strlen(buf))/2 - 1, " "

 %[*][Input data width][length] type

printf("%*s%s%*s", (width-strlen(buf))/2-1, "", buf, (width-strlen(buf))/2-1," "); means ( width-strlen(buf))/2-1 space, then %s prints buf, and finally prints the remaining spaces

#include <stdio.h>
#include <string.h>

void StringInGrid(int width, int height, const char* s)
{
	int i, k;
	char buf[1000];
	strcpy(buf, s);
	if(strlen(s) > width-2) buf[width-2]=0;
	
	printf("+");
	for(i=0; i < width-2; i++) 
		printf("-");
	printf("+\n");
	
	for(k=1; k < (height-1)/2; k++){
		printf("|");
		for(i=0; i < width-2; i++) 
			printf(" ");
		printf("|\n");
	}
	
	printf("|");
	
//	printf("%*s%s%*s",_____________________________________________);  //填空
	printf("%*s%s%*s", (width - strlen(buf))/2 - 1, " ", buf, (width - strlen(buf))/2 - 1, " ");
	
	printf("|\n");
	
	for(k=(height-1)/2+1; k<height-1; k++){
		printf("|");
		for(i=0;i<width-2;i++) printf(" ");
		printf("|\n");
	}	
	
	printf("+");
	for(i=0;i<width-2;i++) printf("-");
	printf("+\n");	
}

int main()
{
	StringInGrid(20,6,"abcd1234");
	return 0;
}

Question 5: Nine array scores

The nine numbers 1,2,3...9 form a score, and its value is exactly 1/3. How to group it?
The following program implements this function, please fill in the missing code in the underlined part.
Note: Only fill in the missing content, do not write any existing codes or explanatory text on the title.

 答案:{t=x[k]; x[k]=x[i]; x[i]=t;}


#include <stdio.h>
 
void test(int x[])
{
	int a = x[0]*1000 + x[1]*100 + x[2]*10 + x[3];
	int b = x[4]*10000 + x[5]*1000 + x[6]*100 + x[7]*10 + x[8];
	
	if(a*3 == b) 
		printf("%d / %d\n", a, b);
}
 
void f(int x[], int k)
{
	int i, t;
	if(k >= 9){
		test(x);
		return;
	}
	
	for(i=k; i<9; i++){
		{t=x[k]; x[k]=x[i]; x[i]=t;}
		f(x,k+1);
//		_____________________________________________ // 填空处
		{t=x[k]; x[k]=x[i]; x[i]=t;}
	}
}
	
int main()
{
	int x[] = {1,2,3,4,5,6,7,8,9};
	f(x, 0);	
	return 0;
}

Question 6 Addition and Multiplication

We all know: 1 + 2 + 3 +... + 49 = 1225 
Now you are required to turn the two non-adjacent plus signs into multiplication signs so that the result is 2015. For
example:
1 + 2 + 3 +... + 10 ∗ 11 + 12 +... + 27 ∗ 28 + 29 +... + 49 = 2015 
is the answer that meets the requirements.
Please look for another possible answer and submit the number to the left of the multiplication sign in the front position (for example, submit 10 1010).
Note: What you need to submit is an integer, do not fill in any extra content.

Answer: 16 

#include <iostream>
using namespace std;

void solve(){
	int first, second;
	for(first = 1; first <= 48; first++){
		if(first == 10){
			continue;
		}
		for(second = first + 2; second <= 48; second++){
			int res = 0, i = 1;
			while(i <= 49){
				if((i == first) || i == second){
					res += i * (i+1);
					i += 2;
				}else{
					res += i;
					i++;
				}
			}
			if(res == 2015){
				cout << first;
			}
		}
	}
}

int main(int argc, char** argv) {
	solve();
	return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_44566432/article/details/115055890