01 #include <iostream>
02 #include <string>
03 using namespace std;
04
05 char base[64];
06 char table[256];
07
08 void init()
09 {
10 for (int i = 0; i < 26; i++) base[i] = 'A' + i;
11 for (int i = 0; i < 26; i++) base[26 + i] = 'a' + i;
12 for (int i = 0; i < 10; i++) base[52 + i] = '0' + i;
13 base[62] = '+', base[63] = '/';
14
15 for (int i = 0; i < 256; i++) table[i] = 0xff;
16 for (int i = 0; i < 64; i++) table[base[i]] = i;
17 table['='] = 0;
18 }
19
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”。( )
设输入字符串长度为 n,decode 函数的时间复杂度为( )。
Θ(n)
Θ(n log n)
Θ(n2)
当输入为“Y3Nx”时,输出的第二行为( )。
“csp”
“csq”
“CSP”
“Csp”
当输入为“Y2NmIDIwMjE=”时,输出的第二行为( )。
“ccf2021”
“ccf2022”
“ccf 2021”
“ccf 2022”