#ACSP1011. cspj-模拟题11

cspj-模拟题11

一、单项选择题

  1. 一个浮点型变量占用({{ select(1) }})个字节。
  • 4
  • 8
  • 16
  • 128
  1. 设有n个已排好序的数据元素,采用折半查找时,最大比较次数为({{ select(2) }})。
  • (log_2n)
  • (n)
  • (n^2)
  • (n-1)
  1. 现有两张分辨率为2048×2048像素的24位真彩色图像。要存储这两张图像,需要({{ select(3) }})的存储空间。
  • 32MB
  • 64MB
  • 128MB
  • 256MB
  1. 二进制数1011.11转成十进制数是({{ select(4) }})。
  • 11.55
  • 11.75
  • 13.55
  • 13.75
  1. 设简单无向图G有20条边且每个顶点的度数都是4,则图G有({{ select(5) }})个顶点。
  • 5
  • 10
  • 20
  • 40
  1. 周末徐老师和爸爸妈妈三个人一起想动手做三道菜。假设做每道菜的顺序都是:先洗菜4分钟,然后切菜8分钟,最后炒菜12分钟。那么做完三道菜的最短时间需要({{ select(6) }})分钟。
  • 85
  • 90
  • 120
  • 135
  1. 表达式 (a + b) * (c + d) + e 的后缀形式是({{ select(7) }})。
  • a + b c + d * + e
  • a b c d + + * + e
  • a b + c d + * e +
  • a b + c d + e + *
  1. 字符串"hetao"的子串个数是({{ select(8) }})。
  • 10
  • 15
  • 16
  • 20
  1. 对于入栈顺序为a, b, c, d, e, f, g的序列,下列({{ select(9) }})可能是其合法的出栈序列。
  • a, b, c, g, f, d, e
  • c, b, a, f, d, e, g
  • c, b, f, g, e, d, a
  • g, f, e, d, a, b, c
  1. 设(x = \text{true}), (y = \text{false}), (z = \text{true}),以下逻辑表达式值为真的是({{ select(10) }})。
  • (x∧y)∨(y∧z)
  • x∧y∧(y∨z)
  • (x∨y)∧(y∧z)
  • (x∨y)∧(y∨z)
  1. 一棵具有8层的满二叉树中结点数为({{ select(11) }})。
  • 128
  • 255
  • 256
  • 511
  1. 一个字长为8位的整数的补码是11011010,则它的原码是({{ select(12) }})。
  • 11011010
  • 11010101
  • 11010110
  • 10110011
  1. 一棵二叉树的先序遍历序列是ABCDEFG,中序遍历序列是DCBEAFG,则这个二叉树的后序遍历序列为({{ select(13) }})。
  • CDFEGBA
  • CFDBEAG
  • DCEBGFA
  • CFBDEGA
  1. 设哈希表的地址空间为0到10,散列函数为(hash(n) = n \mod 11),用线性探查法解决碰撞。现从空的哈希表开始,依次插入关键码值84, 25, 38, 57, 71,则最后一个关键码的地址为({{ select(14) }})。
  • 71
  • 7
  • 6
  • 5
  1. 3名医生和6名护士被分配到3所学校为学生体检,每校分配1名医生和2名护士,不同的分配方法共有({{ select(15) }})种。
  • 360
  • 540
  • 720
  • 960

二、阅读程序

第一小题

#include <cstdio>
#include <cstring>
using namespace std;
char s[101];
int n, cnt[26];
int main() {
    scanf("%s", s);
    n = strlen(s);
    for (int i = 0; i < n; i++) {
        if (s[i] >= 'A' && s[i] <= 'Z')
            cnt[s[i]-'A']++;
        if (s[i] >= 'a' && s[i] <= 'z')
            cnt[s[i]-'a']++;
        if (s[i] >= '0' && s[i] <= '9')
            cnt[s[i]-'0']++;
    }
    int p = 0;
    for (int i = 1; i < 26; i++)
        if (cnt[i] > cnt[p])
            p = i;
    printf("%d\n", p);
    return 0;
}

假设输入的字符串长度不超过100,完成下面的判断题和单选题:

16.输入的字符串只能由小写字母或大写字母组成。({{ select(16) }})

  • ×

17.将第10行的i < n改成i <= n,程序运行时可能会发生错误。({{ select(17) }})

  • ×

18.将第12行的s[i] >= 'a' && s[i] <= 'z'改成s[i] >= 'a',程序运行时可能会发生错误。({{ select(18) }})

  • ×

19.若输入的字符串全部由数字字符组成,则输出的整数必然小于10。({{ select(19) }})

  • ×

20.若输入为ABCDcbaAcDbC,输出为({{ select(20) }})。

  • 0
  • 1
  • 2
  • 3

21.若输入为a2B3233CCDC,输出为({{ select(21) }})。

  • 0
  • 1
  • 2
  • 3

第二小题

#include <iostream>
using namespace std;
int f(int n, int m) {
    if (n == 1) return m;
    if (m == 1) return n;
    int res = 0;
    for (int i = 1; i < n; i++)
        for (int j = 1; j < m; j++)
            res += f(i, j);
    return res;
}
int main() {
    int n, m;
    cin >> n >> m;
    cout << f(n, m) << endl;
    return 0;
}

22.计算f(n, m)的时间复杂度为O(nm)({{ select(22) }})。

  • ×

23.去掉第6行的代码,程序将会不停地递归调用而不会返回结果。({{ select(23) }})

  • ×

24.同时去掉第6行和第7行的代码,程序将会不停地递归调用而不会返回结果。({{ select(24) }})

  • ×

25.当输入为5 6时,输出为({{ select(25) }})。

  • 92
  • 143
  • 166
  • 175

26.当输入为100 2时,输出为({{ select(26) }})。

  • 3762
  • 4950
  • 5050
  • 6689

27.当去掉程序中的第6行,且输入为3 6时,输出为({{ select(27) }})。

  • 0
  • 7
  • 25
  • 43

第三小题

#include <cstring>
using namespace std;
char s[1000];
int f[1000][8], n, x, y;
int Log2(int x) {
    int a = 0, b = 1;
    while (b*2 <= x) {
        a++;
        b *= 2;
    }
    return a;
}
int main() {
    cin >> s >> x >> y;
    n = strlen(s);
    for (int i = 0; i < n; i++)
        f[i][0] = s[i];
    for (int i = 1; (1<<i) <= n; i++)
        for (int j = 0; j+(1<<i)-1 < n; j++)
            f[j][i] = max(f[j][i-1], f[j+(1<<i-1)][i-1]);
    int z = Log2(y-x+1);
    cout << (char)max(f[x][z], f[y-(1<<z)+1][z]) << endl;
    return 0;
}

28.当输入为CGFCDBAE 2 6时,输出为G。({{ select(28) }})

  • ×

29.当输入的第一个字符串的长度为500时,会发生数组越界。({{ select(29) }})

  • ×

30.交换第18行和第19行的代码并不会影响程序的输出结果。({{ select(30) }})

  • ×

31.Log2(15)的返回值为({{ select(31) }})。

  • 2
  • 3
  • 4
  • 5

32.当输入为HETAOACCEPT 0 9时,输出结果为({{ select(32) }})。

  • H
  • E
  • P
  • T

33.当输入为CodeInHETAO 4 10时,输出结果为({{ select(33) }})。

  • I
  • n
  • T
  • O

三、完善程序

第一小题

(排序问题)徐老师发明了一个排序算法,用于将n个整数从小到大排序后输出。下面是他编写的排序代码,但是有一部分丢失了。 试补全下方的排序代码,使其能够将n个整数从小到大排序后输出。

#include <iostream>
using namespace std;
int main() {
    int n, a[101], i, t;
    cin >> n;
    for (i = 0; i < n; i++)
        cin >> a[i];
    ___ (1) ___ = 1;
    while ( ___ (2) ___ ) {
        if (i==0 || ___ (3) ___ ) {
            i++;
        }
        else {
            t = a[i];
            a[i] = ___ (4) ___ ;
            a[i-1] = t;
            ___ (5) ___ ;
        }
    }
    for (i = 0; i < n; i++)
        cout << a[i] << endl;
    return 0;
}

34._ (1) _ 处应填({{ select(34) }})

  • i
  • n
  • t
  • a[0]

35._ (2) _ 处应填({{ select(35) }})

  • i > 0
  • i > 1
  • i < n
  • i <= n

36._ (3) _ 处应填({{ select(36) }})

  • a[i - 1] <= a[i]
  • a[i - 1] >= a[i]
  • a[i] <= a[i + 1]
  • a[i] >= a[i + 1]

37._ (4) _ 处应填({{ select(37) }})

  • a[0]
  • a[i - 1]
  • a[i + 1]
  • a[n - 1]

38._ (5) _ 处填写({{ select(38) }})可以使程序运行得最快。

  • i = 0
  • i = 1
  • i--
  • i++

第二小题

(上一个排列问题)给定一个由1到n构成的排列a,求a的上一个排列。特别地,若输入的排列没有上一个排列,输出-1。 试补全下面的模拟上一个排列的程序。

#include <iostream>
#include <algorithm>
using namespace std;
int n, a[1000];
bool cmp(int a, int b) {
    return ___(1)___ ;
}
bool pre_permutation(int a[], int n) {
    int i = n-1;
    while (i > 0 && a[i-1] < a[i])
        i--;
    if ( ___(2)___ )
        return false;
    for (int j = i; j < n; j++) {
        if (j == n-1 || ___(3)___ ) {
            swap( ___(4)___ , a[j]);
            break;
        }
    }
    sort( ___(5)___ , a+n, cmp);
    return true;
}
int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    if (pre_permutation(a, n)) {
        for (int i = 0; i < n; i++)
            cout << a[i] << " ";
    }
    else {
        cout << -1 << endl;
    }
    return 0;
}

39._ (1) _ 处应填({{ select(39) }})

  • a == b
  • a > b
  • a < b
  • a + b

40._ (2) _ 处应填({{ select(40) }})

  • !i
  • i = 1
  • i == 1
  • i > 1

41._ (3) _ 处应填({{ select(41) }})

  • a[j] == a[i]
  • a[j] < a[j + 1]
  • a[j + 1] > a[i - 1]
  • a[j + 1] > a[i]

42_ (4) _ 处应填({{ select(42) }})

  • a[0]
  • a[i - 1]
  • a[i]
  • a[j + 1]

43._ (5) _ 处应填({{ select(43) }})

  • a + i
  • a + i - 1
  • a + i + 1
  • a + j