#2581. 2022 CSP-S1 真题 · 阅读程序3
2022 CSP-S1 真题 · 阅读程序3
2022 CSP-S1 真题(120 分钟,总分 100 分)
阅读程序3(共 6 题,共 13.5 分)
1.
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXL = 1000;
int n, k, ans[MAXL];
int main(void)
{
cin >> n >> k;
if (!n) cout << 0 << endl;
else
{
int m = 0;
while (n)
{
ans[m++] = (n % (-k) + k) % k;
n = (ans[m - 1] - n) / k;
}
for (int i = m - 1; i >= 0; i--)
cout << char(ans[i] >= 10 ?
ans[i] + 'A' - 10 :
ans[i] + '0');
cout << endl;
}
return 0;
}
假设输入的 n 在 int 范围内,k 为不小于 2 且不大于 36 的正整数,完成下面的判断题和 单选题:
该算法的时间复杂度为O(logkn)。
{{ select(1) }}
- 正确
- 错误
2. 删除第23行的强制类型转换,程序的行为不变。
{{ select(2) }}
- 正确
- 错误
3. 除非输入的n为0,否则程序输出的字符数为 O(\lfloor \logk |n| \rfloor + 1)。
{{ select(3) }}
- 正确
- 错误
4. 当输入为“100 7”时,输出为( )。
{{ select(4) }}
- 202
- 1515
- 244
- 1754
5. 当输入为“-255 8”时,输出为“( )”。
{{ select(5) }}
- 1400
- 1401
- 417
- 400
6. 当输入为“1000000 19”时,输出为“( )”。
{{ select(6) }}
- BG939
- 87GIB
- 1CD428
- 7CF1B
相关
在下列比赛中: