Analysis of C++ Exam Questions from GESP Level 3 – June 2023

Multiple Choice Questions

Question 1: Programs written in high-level languages need to go through the following ( ) operation to generate executable code that can run on a computer.

A. Edit

B. Save

C. Debug

D. Compile

[Answer] D

[Explanation] Computer Fundamentals; Compile –> Run.

Question 2: The binary number 11.01 is ( ) in decimal.

A. 3.01

B. 3.05

C. 3.125

D. 3.25

[Answer] D

[Explanation] Base Conversion Problem

Question 3: The hexadecimal representation of the ASCII code of the uppercase character ‘A’ is 0x41, so the hexadecimal representation of the ASCII code for character ‘F’ is ( ).

A. 46

B. 47

C. 48

D. 49

[Answer] A

[Explanation] A~F, 41+5=46, in hexadecimal it is 0x46.

Question 4: Which of the following is not an operator in C++? ( )

A. &

B. &&

C. *

D. **

[Answer] D

[Explanation] Examination of Operators

Option A: & bitwise operator;

Option B: && logical AND operator;

Option C: * (multiplication) arithmetic operator/pointer;

Option D: not an operator.

Question 5: If a string is defined as char str[] = “Hello”;, then the length of the character array str is ( ).

A. 0

B. 5

C. 6

D. 7

[Answer] C

[Explanation] Examination of Strings

The length of the string is 5 (‘H’, ‘e’, ‘l’, ‘l’, ‘o’);

The length of the character array is 6 (‘H’, ‘e’, ‘l’, ‘l’, ‘o’, ‘/0’).

Question 6: An array defined as double array[3]; occupies ( ) bytes of memory.

A. 24

B. 12

C. 6

D. 3

[Answer] A

[Explanation] 1 byte = 8 bits, 3*8=24, hence option A.

bool
char occupies 1 Byte;

int occupies 4 Bytes;

double / long long occupies 8 bytes.

Question 7: Which of the following array definitions complies with C++ syntax? ( ).

A. int a[ ];

B. int b[‘3’];

C. int c[3.0] ;

D. int[3] d;

[Answer] B

[Explanation] Definition of Arrays

Question 8: Which of the following statements about bases is incorrect? ( ).

A. In the binary representation of positive integers, only 0 and 1 will appear.

B. 10 is not an integer power of 2, so decimal numbers cannot be converted to binary.

C. When converting from binary to octal, it is convenient to convert every 3 binary bits to the corresponding one octal bit from low to high.

D. When converting from binary to hexadecimal, it is convenient to convert every 4 binary bits to the corresponding one hexadecimal bit from low to high.

[Answer] B

[Explanation] Conversion between bases

Option B: The binary of 10 is 1010, and it can be converted to binary.

Question 9: Which of the following statements about arrays in C++ is incorrect? ( ).

A. Arrays must be defined before use.

B. All elements of an array are stored continuously in memory.

C. Except for character arrays, there must be a constant in the [ ] when defining arrays.

D. Arrays cannot be assigned, but each basic type element of the array can be assigned.

[Answer] C

[Explanation] Examination of Arrays;In defining arrays, it is not necessary to have a constant in the [ ].

Question 10: Which operation on an int type value will certainly return it to its original value? ( ).

A. Left shift 3 bits, then right shift 3 bits.

B. Right shift 3 bits, then left shift 3 bits.

C. Bitwise OR 7, then bitwise AND -8.

D. Bitwise XOR 7, then bitwise XOR 7.

[Answer] D

[Explanation] Application of Bitwise Operations

Analysis of C++ Exam Questions from GESP Level 3 - June 2023

Properties:

① Commutative Law

② Associative Law

③ Reflexive Law

Left shift <<, equivalent to multiplying by 2;

Right shift >>, equivalent to dividing by 2.

Question 11: If both a and b are int type variables, which of the following expressions can correctly determine “a equals b”? ( ).

A. ((a / b) == 1)

B. ((a & b) == a)

C. ((a ^ b) == 0)

D. ((a | b) == b)

[Answer] C

[Explanation]

Option A: Counterexample 7/4=1;

Option C, only when the two numbers are the same can XOR result in the same binary for each bit, examining the definition.

Question 12: If a is an int type variable, which of the following expressions can correctly find the largest integer satisfying “less than or equal to a and is a multiple of 4”? ( ).

A. (a & (~3))

B. ((a << 2) >> 2)

C. (a ^ 3)

D. ((a – 1) | 3) + 1

[Answer] A

[Explanation] Use of Bitwise Operations

Question 13: Fill in the blank in the following code to produce the output “24 12”.

Analysis of C++ Exam Questions from GESP Level 3 - June 2023

A. a = a ^ b

B. b = a ^ b

C. a = a + b

D. b = a + b

[Answer] B

[Explanation] Swap Operation; Using XOR method to swap.

Question 14: Fill in the blank in the following code to produce the output “2”.

Analysis of C++ Exam Questions from GESP Level 3 - June 2023

A. min > array[i]

B. min < array[i]

C. min = array[i]

D. None of the above

[Answer] D

[Explanation]

Option A: The output result is 0;

Option B: The output result is 7;

Option C: The output result is 4;

Option D: In summary, none of the above is correct.

Question 15: Fill in the blank in the following code to ensure that the output is not “31”.

Analysis of C++ Exam Questions from GESP Level 3 - June 2023

A. res = res + array[i]

B. res = res & array[i]

C. res = res | array[i]

D. res = res ^ array[i]

[Answer] B

[Explanation]

1 in binary is 1;

2 in binary is 10;

4 in binary is 100;

8 in binary is 1000;

16 in binary is 10000.

True or False Questions

Question 1: An algorithm can be described in different forms, but it must be described in a standardized way, so it cannot be described in natural language.

Correct

Incorrect

[Answer] ×

[Explanation]It can be described in natural language, natural language and algorithms are unrelated. An algorithm outputs results within a limited time (finite steps).

Question 2: A domain name is identified by a string of names separated by dots that marks the name of a computer or group of computers on the Internet. The domain name of the official website of CCF programming ability level certification is gesp.ccf.org.cn, where the top-level domain name is gesp.

Correct

Incorrect

[Answer] ×

[Explanation]gesp is a subdomain.

Question 3: There are only three types of data encoding methods: original code, inverse code, and complement code.

Correct

Incorrect

[Answer] ×

[Explanation]Data encoding methods are not limited to original code, inverse code, and complement code, but also include ASCII, etc.

Question 4: In C++, for an array of length n, the reasonable index range is from 0 to n, including 0 and n.

Correct

Incorrect

[Answer] ×

[Explanation]The last element should be n-1, so the range is 0~n-1.

Question 5: The character constant ‘\0’ is commonly used to indicate the end of a string, and it is different from the character constant ‘0’.

Correct

Incorrect

[Answer] √

Question 6: In C++, a character (like ‘0’) can be used as an array index.

Correct

Incorrect

[Answer] √

Question 7: In C++, when an array is defined, its size is determined.

Correct

Incorrect

[Answer] √

[Explanation] Definition of Arrays

Question 8: Data stored in a computer is always in binary form. Therefore, when writing programs in C++, converting all decimal numbers to their equivalent binary numbers will make the program run more efficiently.

Correct

Incorrect

[Answer] ×

[Explanation]There is a compilation stage before execution, and converting decimal numbers to their equivalent binary numbers does not change the running efficiency.

Question 9: In C++, the value of the expression (0xf == 015) is true.

Correct

Incorrect

[Answer] ×

[Explanation]f is a hexadecimal number (15), while 015 is an octal number (0*8+5=13), hence false.

Question 10: If a is an int type variable, and the value of the expression ((a | 3) == 3) is true, then it indicates that a is between 0 and 3 (it can be 0 or 3).

Correct

Incorrect

[Answer] √

[Explanation]a is between 00~11.

Programming Questions

Question 1: Spring Outing

[Problem Description]

The teacher leads the students on a spring outing. It is known that there are N students in the class, each with a unique number from 0 to N – 1. When it is time to gather, the teacher checks whether all students have arrived at the gathering place, and asks the students to report their numbers. Students who have arrived will report their numbers, and will not report anyone else’s number, but some students may play tricks and report their numbers multiple times. Can you help the teacher find out which students have not arrived?

[Input Description]

The input consists of 2 lines. The first line contains two integers N and M, indicating that there are N students in the class, and the students have reported their numbers M times, with the stipulation that 2≤N,M≤1000. The second line contains M integers, which are the reported numbers. All reported numbers are within a reasonable range.

[Output Description]

Output one line. If all students have arrived, output N; otherwise, output all the numbers of students who have not arrived, sorted in ascending order, separated by spaces.

[Sample Input 1]

3 3

0 2 1

[Sample Output 1]

3

[Sample Input 2]

3 5

0 0 0 0 0

[Sample Output 2]

12

Question 2: Password Compliance Check

[Problem Description]

Website registration requires a username and password, write a program to check the validity of the password entered by the user. Compliant passwords must meet the following requirements:

1. Can only consist of 26 lowercase letters from a-z, 26 uppercase letters from A-Z, 10 digits from 0-9, and four special characters: !@#$.

2. Minimum password length: 6 characters, maximum length: 12 characters.

3. At least two of uppercase letters, lowercase letters, and digits must be included, along with at least one of the four special characters.

[Input Description]

The input is a single line string without spaces. The length is not more than 100. This string is divided into multiple segments by commas, serving as multiple groups of passwords to be checked.

[Output Description]

Output several lines, each line outputs a compliant password.

The output order is the same as the input order, i.e., the first input is output first.

[Sample Input 1]

seHJ12!@,sjdkffH$123,sdf!@&12HDHa!,123&^YUhg@!

[Sample Output 1]

seHJ12!@

sjdkffH$123

[Sample Explanation 1]

The input is divided into four groups of passwords to be checked: “seHJ12!@”, “sjdkffH$123”, “sdf!@&12HDHa!”, “123&^YUhg@!”. Among them, “sdf!@&12HDHa!” exceeds 12 characters and is non-compliant; “123&^YUhg@!” contains characters outside the four special characters and is non-compliant.

Selected from Previous Issues

Analysis of C++ Exam Questions from GESP Level 3 - June 2023 Analysis of C++ Exam Questions from GESP Level 3 - June 2023

[CSP-J/S Informatics Training Camp]

All-Star Coach Team

Analysis of C++ Exam Questions from GESP Level 3 - June 2023

[Informatics Monthly Competition]

CSP-J June Mock Contest Question Analysis

Analysis of C++ Exam Questions from GESP Level 3 - June 2023

14th Blue Bridge Cup National Competition for Youth

C++ Exam Question Analysis

Analysis of C++ Exam Questions from GESP Level 3 - June 2023

Analysis of C++ Exam Questions from GESP Level 3 - June 2023

Leave a Comment