Hello, little lambs! Starting today, I will bring you an analysis of the GESP-C++ Level 3 exam questions. As for why it’s Level 3, that’s because you passed Level 1 with a high score! I hope that through this sharing, you can suddenly understand a common mistake that is useful!Here, I will not provide answers to programming questions, but I will point out important considerations or thought processes. If you have any questions, feel free to comment, and if you’re in a hurry, you can also add my personal WeChat (ldw_0711) to ask.First and foremost, I hope you can complete the exam according to the time requirements before checking the analysis!How to obtain the exam questions:
Through the file shared on the cloud: 2023 GESP C++ Level 3 June Exam Questions (without answers).pdf
Link: https://pan.baidu.com/s/1XO8teZc4BU2LLd_n5Z3JtA?pwd=ldw0 Extraction code: ldw0
1. Multiple Choice Questions
1. The compilation generates the corresponding executable file
The answer is D
2. Recall how to convert binary to decimal:
The part before the decimal point is multiplied by 2 from back to front, and the part after the decimal point is divided by 2 from front to back
1*2^0 + 1*2^1 + 0*2^-1 + 1*2^-2 = 1 + 2 + 0.25 = 3.25
The answer is D
3. ‘A’: 65 ‘F’: 70 Convert to hexadecimal: 0x46 (shift five bits to the right) or:
70%16=6 70/16=4
4%16=4 4/16=0
Take all remainders in reverse: 46, add the hexadecimal prefix – 0x46
The answer is A
4. There is no power operator in C++, use pow()
The answer is D
5. The string also has an end identifier ‘\0’
The answer is C
6. A double is 8 bytes, three of them is 24
The answer is A
7. Characters are interpreted as their ASCII values at compile time
The answer is B
8.
The answer is B
9. If assigned at definition, you can use [], for example:
int a[]={1,2,3,4,5};
The answer is C
10. Properties of XOR in bitwise operations:
Commutative: a ^ b = b ^ a
Associative: (a ^ b) ^ c = a ^ (b ^ c)
Self-inverse: a ^ a = 0
Zero law: a ^ 0 = a
a^7^7=a^(7^7)=a^0=a
The answer is D
11. First exclude options A and D, then option B checks if a is a subset of b
Option C looks at the self-inverse property of XOR, it only returns 0 when both numbers are the same, otherwise it returns non-zero
The answer is C
12. Suppose a=4,
A is 100 100&100=100
B100
C100^011=111
D011|011=011
Assuming another 5, enter circle A, B, D
A101&100=100
B101 is out!
D100|011=111 unfortunately out!
The answer is A
13.a b
1100 11000
A:
a=a^b=01100^11000
10100 20
a=a^b=10100^11000
01100 12
b=a^b=01100^11000
10100 20
B:
b=01100^11000=10100
a=01100^10100=11000
b=11000^10100=01100
The answer is B
14. Pay attention to the initialization of extreme value variables:
To find the maximum value, initialize to a very small value or the first element of the array;
To find the minimum value, initialize to a very large value or the first element of the array
The answer is D
15. The initial value is 0, bitwise AND with 1, 2, 4, 8, 16 still results in 0
The answer is B
2. True or False Questions
1. Algorithms can be described not only in programming languages but also in natural language
The answer is ×
2. A domain name consists of two or more words separated by dots, with the rightmost word being the top-level domain:
.cn (top-level domain), .org (second-level domain, non-profit organization category), .ccf (third-level domain, abbreviation for China Computer Federation), gesp (fourth-level domain, specific service identifier)
The answer is ×
3. Original code, inverse code, and complement code are three common encoding methods for signed integers in computers, along with others such as: ASCII, UTF-8, GBK, Huffman coding, etc.
The answer is ×
4. The subscript goes to n-1
The answer is ×
5. Correct
The answer is √
6. Characters will be converted to corresponding ASCII
The answer is √
7. Correct, but dynamic arrays have an automatic expansion mechanism
The answer is ×
8. The C++ compiler will convert literals (such as 10, 0b1010, 0xA) in the source code into binary machine code recognizable by the computer during the compilation phase
The answer is ×
9. Numbers starting with 0 are octal: 015=5*8^0+1*8^1=13
The answer is ×
10. 0|11=0
The answer is ×
3. Programming Questions
Little reminder: For programming questions, I think it’s best for you to have your own thoughts and ideas first. Of course, you can refer to my ideas, and if any students need specific code, I will consider posting it in the comments.
1. Spring Outing (2023 GESP C++ Level 3 June First Question)
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. At the gathering time, the teacher checks whether all students have arrived at the meeting place and asks them to report their numbers. The students who arrive will report their numbers, and will not report others’ numbers, but some students are mischievous and may report multiple times. Can you help the teacher find out which students did not arrive?
Input
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 reported their numbers M times. It is stipulated that 2 ≤ N, M ≤ 1000. The second line contains M integers, which are the reported numbers. It is stipulated that all numbers are within a reasonable range.
Output
Output one line. If all students have arrived, output N; otherwise, output all the numbers of students who did not arrive in ascending order, separated by spaces.
Sample Input
3 3
0 2 1
Sample Output
3
[Solution Idea]
1. You can use an array a to store all reported numbers, and another array b to check if each number has been reported, remember to initialize it.
2. Traverse the reported number array a, and array b records the reporting flags, another variable counts the number of arrivals.
3. Compare with the total number of students:
All arrived – output N;
Otherwise, output the numbers of those who did not arrive in ascending order according to the flags.
[Knowledge Points] Loops, Arrays, Simulation
2. Password Compliance Check (2023 GESP C++ Level 3 June Second Question)
Problem Description
Website registration requires a username and password. Write a program to check the validity of the user-input password.
A compliant password must meet the following requirements:
1. It can only consist of 26 lowercase letters a-z, 26 uppercase letters A-Z, 10 digits 0-9, and four special characters !@#$.
2. Minimum password length: 6 characters, maximum password length: 12 characters.
3. At least two of uppercase letters, lowercase letters, and digits must be present, and at least one of the four special characters must be included.
Input
The input is a single line string without spaces. It is stipulated that the length does not exceed 100. The string is separated by commas into multiple segments, serving as multiple groups of passwords to be checked.
Output
Output several lines, each line outputs a compliant password. The output order is the same as the input order, meaning the first input is the first output.
Sample Input
seHJ12!@,sjdkffH$123,sdf!@&12HDHa!,123&^YUhg@!
Sample Output
seHJ12!@
sjdkffH$123
[Solution Idea]
This question mainly involves checking the three conditions separately. It is recommended to first check the length condition; if it does not meet, there is no need to check other conditions.
You can put the three conditions in one function, but if you can’t clarify them all at once, you can also split them into three functions.
Note that the last string also needs to be checked.
[Knowledge Points] Loops, Strings, Simulation
Finally,
If you are interested or are also learning programming, feel free to add Lazy King’s personal WeChat (ldw_0711), and I hope to provide some help on your programming journey!