#4346. CSP 2021 普及组级第一轮:阅读程序第二题

CSP 2021 普及组级第一轮:阅读程序第二题

#include <iostream>
#include <string>
using namespace std;

char base[64];
char table[256];

void init()
{
    for (int i = 0; i < 26; i++) base[i] = 'A' + i;
    for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;
    for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;
    base[62] = '+', base[63] = '/';

    for (int i = 0; i < 256; i++) table[i] = 0xff;
    for (int i = 0; i < 64; i++) table[base[i]] = i;
    table['='] = 0;
}
20 string decode(string str)
21 {
22    string ret;
23    int i;
24    for (i = 0; i < str.size(); i += 4) {
25        ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;
26        if (str[i + 2] != '=')
27            ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;
28        if (str[i + 3] != '=')
29            ret += table[str[i + 2]] << 6 | table[str[i + 3]];
30    }
31    return ret;
32 }
33
34 int main()
35 {
36    init();
37    cout << int(table[0]) << endl;
38
39    string str;
40    cin >> str;
41    cout << decode(str) << endl;
42    return 0;
43 }

判断题和单选题:

判断题

1输出的第二行一定是由小写字母、大写字母、数字和“+”、“/”、“=”构成的字符串。( )

{{ select(1) }}

  • 正确
  • 错误

2、可能存在输入不同,但输出的第二行相同的情形。( )

{{ select(2) }}

  • 正确
  • 错误

3、输出的第一行为“-1”。( )

{{ select(3) }}

  • 正确
  • 错误

单选题:

4、设输入字符串长度为 n,decode 函数的时间复杂度为( )。

{{ select(4) }}

  • O(根号n)
  • O(n)
  • O(nlogn)
  • O(n^2)

5、当输入为“Y3Nx”时,输出的第二行为( )。

{{ select(5) }}

  • “csp”
  • “csq”
  • “CSP”
  • “Csp”

6、当输入为“Y2NmIDIwMjE=”时,输出的第二行为( )。

{{ select(6) }}

  • “ccf2021”
  • “ccf2022”
  • “ccf 2021”
  • “ccf 2022”