Summary of basic exercise questions for the Blue Bridge Cup

BASIC-1 Leap Year Judgment

Given a year, judge whether the year is a leap year.

When one of the following conditions is met, the year is a leap year:

  1. The year is a multiple of 4 instead of a multiple of 100;
  1. The year is a multiple of 400.

The other years are not leap years.

Input format The
input contains an integer y, which represents the current year.
Output format
Output one line, if the given year is a leap year, output yes, otherwise output no.
Note: When the test question specifies that you output a string as the result (such as yes or no in this question, you need to strictly follow the capitalization given in the test question, and the wrong capitalization will not be scored.

Sample input
2013
sample output
no
sample input
2016
sample output
yes
Data size and convention
1990 <= y <= 2050.

Problem-solving code:

#include<iostream>
using namespace std;
int main()
{
    
    
	
	int y;
	cin>>y;
	if(((y%4==0)&&(y%100)!=0)||(y%400)==0){
    
    
		cout<<"yes"<<endl;
	}else{
    
    
		cout<<"no"<<endl;
	}
	return 0;
}

BASIC-2 01 string

Title description:

For a 01 string with a length of 5 bits, each bit may be 0 or 1, and there are 32 possibilities. The first few of them are:

00000

00001

00010

00011

00100

Please output these 32 kinds of 01 strings in ascending order.

Input format
There is no input for this question.
Output format
32 lines are output, with a 01 string of length 5 for each line in ascending order.
Sample output

00000
00001
00010
00011

<The following parts are omitted>
Problem-solving code:

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    
    
	for(int a=0;a<2;a++){
    
    
		for(int b=0;b<2;b++){
    
    
			for(int c=0;c<2;c++){
    
    
				for(int d=0;d<2;d++){
    
    
					for(int e=0;e<2;e++){
    
    
						cout<<a<<b<<c<<d<<e<<endl;
					}
				}
			}
		}
	}
    
	return 0;
}

BASIC-3 letter graphics

Letters can be used to form some beautiful graphics, an example is given below:

ABCDEFG

BABCDEF

CBABCDE

DCBABCD

EDCBABC

This is a graph with 5 rows and 7 columns. Please find out the pattern of this graph and output a graph with n rows and m columns.

Input format
Input one line, which contains two integers n and m, respectively representing the number of rows and columns of the graphics you want to output.
Output format
Output n lines, each m characters, for your graphics.
Sample input

5 7

Sample output

ABCDEFG
BABCDEF
CBABCDE
DCBABCD
EDCBABC

Data size and convention
1 <= n, m <= 26.
Problem-solving code:

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    
    
	int n,m;
	cin>>n>>m;
	char begin='A';
	for(int i=0;i<n;i++){
    
    
		for(int j=0;j<m;j++){
    
    
			char a=begin+abs(i-j);
			cout<<a;
		}
		cout<<endl;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_44867340/article/details/108953296