Analysis of past CSP-J preliminary test questions | 2023 CSP-J preliminary test single-choice questions (1-15)

Learn C++ from a young age! Record the questions in the CSP-J exam preparation study process and record every moment.

Attached is a summary post: Analysis of past CSP-J preliminary test questions | Summary_csp past past questions_Blog of a communicator who loves programming-CSDN blog


1. In C++, which of the following keywords is used to declare a variable whose value cannot be modified? ( )

A.unsigned

B.const

C.static

D.mutable

[Answer]: B

【Analysis】

Unsigned means unsigned, static static variables maintain their existence and value while the program is running, and mutable-modified variables will always be in a mutable state. Variables modified by const cannot be updated

2. The sum of octal numbers 12345670(8) and 07654321(8) is ( )

A.22222221(8)

B.21111111(8)

C.22111111(8)

D.22222211(8)

[Answer]: D

【Analysis】

Refer to the decimal calculation method, octal system is to add eight to one, 1234567890(8)+07654321(8)=22222211(8)

3. Read the following code. Please modify the value member of data to store 3.14. The correct way is ( )

union Data{
    int num;
    float value;
    char symbol;
};

union Data data;

A.data.value = 3.14;

B.value.data = 3.14;

C.data->value = 3.14;

D.value->data = 3.14;

【Answer】:A

【Analysis】

Both union and struct are composed of members of different data types. The memory space occupied by all members of the structure is cumulative, while all members of the union share an address space. You can refer to struct and access its member variables using the type variable name. Member variable name, that is, data.value. ->Used for pointer access. Choose A

4. Suppose there is a linked list node defined as follows:

struct Node {
    int data;
    Node* next;
}

Now there is a pointer to the head of the linked list: Node* head. If you want to insert a new node in the linked list, the value of its member data is 42, and make the new node the first node of the linked list, which of the following operations is correct? of?

A.Node* newNode = new Node; newNode->data = 42; newNode->next = head; head = newNode;

B.Node* newNode = new Node; head->data=42; newNode->next = head; head = newNode;

C.Node* newNode = new Node; newNode->data=42; head->next = newNode;

D.Node* newNode = new Node; newNode->data=42; newNode->next = head;

【Answer】:A

【Analysis】

In the first sentence, the four options are all the same, indicating that the Node type newNode is defined. The second sentence means to set the value of its member's data to 42, using newNode->data = 42. Because newNode needs to be the first node, newNode->next needs to point to the existing head, that is, newNode->next = head. At this time, newNode becomes head, so A has one more sentence than D, head = newNode.

5. The height of the root node is 1, and the height of a ternary tree with 2023 nodes is at least ( )

A.6

B.7

C.8

D.9

[Answer]: C

【Analysis】

"At least" indicates that the minimum height is required. Drawing a complete ternary tree can meet the question requirements. There are 1 node in layer 1, 3 nodes in layer 2, 9 nodes in layer 3, 27 nodes in layer 4, 81 nodes in layer 5, 243 nodes in layer 6, 729 nodes in layer 7, and 8 layers and 2187 nodes. The sum of the first 7 layers is 1093, which is less than 2023. Adding the 8th layer exceeds 2023, so there are at least 8 layers.

6. Xiao Ming has seven free time periods in a certain day. He wants to select at least one free time period to practice singing, but he hopes that there are at least two free time periods between any two practice time periods. Let him rest. Then Xiao Ming has a total of ( ) ways to choose the time period.

A.31

B.18

C.21

D.33

[Answer]: B

【Analysis】

Assume that the seven time periods are 1234567, and the number of combinations of n time periods is enumerated in sequence.

There are 7 ways to select a time period: 1, 2, 3, 4, 5, 6, 7

There are 4+3+2+1=10 ways to choose 2 time periods: 14, 15, 16, 17, 25, 26, 27, 36, 37, 47

There is 1 way to choose 3 time periods: 147

So there are 18 types of moves, choose B

7. Which of the following statements about high-precision operations is wrong ( )

A. High-precision calculations are mainly used to process large integers or operations that require retaining multiple decimal places.

B. The steps for dividing a large integer by a small integer can be to align the dividend and the divisor, try to multiply the divisor by a certain number bit by bit from left to right, obtain a new dividend by subtraction, and accumulate the quotient.

C. The operation time of high-precision multiplication is only related to the number of digits in the longer of the two integers involved in the operation.

D. The key to high-precision addition operations is to add bit by bit and handle carry.

[Answer]: C

【Analysis】

The operation time of high-precision multiplication is related to the product of the lengths of the two integers involved in the operation. Choose C. For specific high-precision calculation implementation, please refer to Luogu P1303 problem solution.

8. The intermediate expression corresponding to the suffix expression "623+-382/+*2^3+" is ( ).

A.((6-(2+3))*(3+8/2))^2+3

B.6-2+3*3+8/2^2+3

C.(6-(2+3))*((3+8/2)^2)+3

D.6-((2+3)*(3+8/2))^2+3

【Answer】:A

【Analysis】

There are three steps to change an infix to a suffix. The first step is to add parentheses, the second step is to move the operator to the right of the parentheses, and the third step is to remove the parentheses. Do the opposite here.

Add brackets: ((((6(23)+)-(3(82)/)+)*2)^3)+

Move the brackets to the middle: ((((6-(2+3))*(3+(8/2)))^2)+3)

Gradually remove the extra brackets and get: ((6-(2+3))*(3+8/2))^2+3

Choose A

9. The sum of the numbers 101010(2) and 166(8) is ( ).

A.10110000(2)

B.236(8)

C.158(10)

D.A0(16)

[Answer]: D

【Analysis】

After uniform conversion to decimal numbers, calculate 101010(2)=42(10), 166(8)=118(10), 160(10)=A0(16)=240(8)=10100000(2), choose D

10. Suppose there is a set of characters {a, b, c, d, e, f}, with corresponding frequencies of 5%, 9%, 12%, 13%, 16%, and 45% respectively. Which of the following options is a set of Huffman codes corresponding to the characters a, b, c, d, e, and f? ( )

A.1111,1110,101,100,110,0

B.1010,1001,1000,011,010,00

C.000,001,010,011,10,11

D.1010,1011,110,111,00,01

【Answer】:A

【Analysis】

Draw the Huffman tree according to Huffman's rules. The f node has no child nodes. Observe the answer A, indicating that f is 0. You can directly select A through the elimination method.

11. Given a binary tree, the result of pre-order traversal is: ABDECFG, and the result of in-order traversal is: DEBACFG. What is the correct post-order traversal result of this tree? ( )

A.EDBGFCA

B.EDGBFCA

C.DEBGFCA

D.DBEGFCA

【Answer】:A

【Analysis】

In-order traversal first visits the left subtree, then the root, and then the right subtree. Preorder traversal first visits the root, then the left subtree, and then the right subtree. Subsequent traversals first visit the left subtree, then the right subtree, and then the root.

According to the pre-order and in-order traversal, a binary tree can be drawn. The post-order traversal is EDBGFCA. Choose A.

12. Consider a directed acyclic graph containing 4 directed edges: (1,2), (1,3), (2,4) and (3,4). Which of the following options is a valid topological ordering of this directed acyclic graph? ( )

A.4,2,3,1

B.1,2,3,4

C.1,2,4,3

D.2,1,3,4

[Answer]: B

【Analysis】

Before accessing 2 and 3, you need to access 1 first. Before accessing 4, you need to access 2 or 3 first. Choose B.

13. In a computer, which of the following options describes the smallest data storage capacity? ( )

A. Byte

B. bit

C. word

D.kilobyte

[Answer]: B

【Analysis】

The smallest unit of computer storage is bit. A word consists of several bits. Choose B

14. There are 10 boys and 12 girls at a meal. If you want to select a group of 3 people, and the group must contain at least 1 girl, how many possible combinations are there? ( )

A.1420

B.1770

C.1540

D.2200

【Answer】A

【Analysis】

Choose 1 girl, combination =C(12,1)*C(10,2)=540

Choose 2 girls, combination =C(12,2)*C(10,1)=660

Choose 3 girls, combination =C(12,3)=220

A total of 1420 combinations

15. Which of the following is not an operating system? ( )

A.Linux

B.Windows

C.Android

D.HTML

[Answer]: D

【Analysis】

HTML is Hypertext Markup Language, not an operating system

Guess you like

Origin blog.csdn.net/guolianggsta/article/details/132940178