CSP-J入門級第一輪認證模擬卷37

您的姓名:
一、單項選擇題(共15題,每題5分,共計75分)
1. 二進制數(shù) `1010` 轉(zhuǎn)換為十進制數(shù)是( )。
2. 以下代碼的輸出是( )。

```cpp

int x = 3;

int *p = &x;

*p = 5;

cout << x;

```  

3. 表達式 `9 | 6` 的值是( )。
4. 以下代碼的輸出是( )。

```cpp

int arr[3] = {0};

cout << arr[1];

```

5. 循環(huán) `for (int i=1; i<=15; i*=2)` 的執(zhí)行次數(shù)是( )。
6. 函數(shù)重載不能基于( )。
7. 以下代碼的輸出是( )。

```cpp

int x = 0;

if (x = 1)

cout << "Yes";

else

cout << "No";

```  

8. 遞歸函數(shù) `f(n)=f(n-1)*n (n>0)` 且 `f(0)=1`,則 `f(4)` 的值是( )。
9. 動態(tài)分配數(shù)組 `int arr[10]` 的關(guān)鍵字是( )。
10. 表達式 `8 << 1` 的值是( )。
11. 以下代碼的輸出是( )。

```cpp

int a = 3, b = 4;

cout << (++a * b--);

```  

12. 二分查找要求數(shù)據(jù)結(jié)構(gòu)是( )。
13. 選擇排序中,更新最小元素下標的代碼是( )。
14. 質(zhì)因數(shù)分解中,循環(huán)變量 `i` 的終止條件是( )。
15. 表達式 `!(3 < 5) || (2 > 4)` 的值是( )。
二、閱讀程序(每題5分,共55分)

**程序1**

```cpp

#include <iostream>

using namespace std;

int main() {

int a = 7, b = 2;

a = a % b;

b = a * b;

cout << a << " " << b;

return 0;

}

```

16. 程序計算 `a` 除以 `b` 的余數(shù)。( )
17. 輸出 `1 2`。( )
18. 輸入 `a=3, b=3`,輸出 `0 0`。( )
19. 若 `a=10, b=3`,輸出是( )。

**程序2**

```cpp

#include <iostream>

using namespace std;

int f(int n) {

if (n <= 1) return n;

return f(n-1) + n;

}

int main() {

cout << f(4);

return 0;

}

```

20. 程序計算 `1+2+...+n`。( )
21. 輸出 `10`。( )
22. 函數(shù) `f` 的時間復雜度是 O(n)。( )
23. `f(0)` 的返回值是( )。

**程序3**

```cpp

#include <iostream>

using namespace std;

int main() {

int cnt = 0;

for (int i=1; i<=20; i++) {

if (i % 4 == 0) continue;

cnt++;

}

cout << cnt;

return 0;

}

```

24. `cnt` 的值是 `15`。( )
25. 若 `i` 從0開始,`cnt` 的值是 `16`。( )
26. `continue` 語句的作用是( )。
三、完善程序(每題5分,共55分)

**程序1(求最大值)**

```cpp

#include <iostream>

using namespace std;

int main() {

int n, max_val = -1000;

cin >> n;

for (int i=0; i<n; i++) {

int x;

cin >> x;

if (x > max_val) ______;

}

cout << max_val;

return 0;

}

```

27. 橫線處應填( )。

**程序2(插入排序)**

```cpp

#include <iostream>

using namespace std;

int main() {

int a[100], n;

cin >> n;

for (int i=0; i<n; i++) cin >> a[i];

for (int i=1; i<n; i++) {

int key = a[i];

int j = i-1;

while (j >= 0 && a[j] > key) {

______;

j--;

}

a[j+1] = key;

}

return 0;

}

```

28. 橫線處應填( )。

**程序3(線性搜索)**

```cpp

#include <iostream>

using namespace std;

int main() {

int arr[] = {2,4,6,8,10};

int x;

cin >> x;

for (int i=0; i<5; i++) {

if (______) {

cout << "Found";

return 0;

}

}

cout << "Not Found";

return 0;

}

```

29. 橫線處應填( )。
更多問卷 復制此問卷