#360. CSP2021PJ-17
CSP2021PJ-17
- (阅读程序)
#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;
}
string decode(string str)
{
string ret;
int i;
for (i = 0; i < str.size(); i += 4) {
ret += table[str[i]] << 2 | table[str[i + 1]] >> 4;
if (str[i + 2] != '=')
ret += (table[str[i + 1]] & 0x0f) << 4 | table[str[i + 2]] >> 2;
if (str[i + 3] != '=')
ret += table[str[i + 2]] << 6 | table[str[i + 3]];
}
return ret;
}
int main()
{
init();
cout << int(table[0]) << endl;
string str;
cin >> str;
cout << decode(str) << endl;
return 0;
}
(判断题)
输出的第二行一定是由小写字母、大写字母、数字和 “+”、“/”、“=” 构成的字符串( )
{{ select(1) }}
- 对
- 错
可能存在输入不同,但输出的第二行相同的情形( )
{{ select(2) }}
- 对
- 错
输出的第一行为 “-1”( )
{{ select(3) }}
- 对
- 错
(选择题)
设输入字符串长度为 n,decode 函数的时间复杂度为( )
{{ select(4) }}
- O()
- O(n)
- O(nlogn)
- O()
当输入为 “Y3Nx” 时,输出的第二行为( )
{{ select(5) }}
- “csp”
- “csq”
- “CSP”
- “Csp”
当输入为 “Y2NmIDIwMjE=” 时,输出的第二行为( )
{{ select(6) }}
- “ccf2021”
- “ccf2022”
- “ccf 2021”
- “ccf 2022”
相关
在下列比赛中: