#12251. 珅泽教育CSP-J第一轮模拟考第二十四套 第 23 题
珅泽教育CSP-J第一轮模拟考第二十四套 第 23 题
二、阅读程序(判断题正确填 A、错误填 B;除特殊说明外,判断题 2 分,选择题 3 分,共计 40 分)
程序二:字符串处理
#include <cstdio>
#include <cstring>
const int maxn = 1003;
int type, n, m;
char s[maxn], t[maxn];
int main() {
scanf("%d %s %s", &type, t, s);
n = strlen(s); m = strlen(t);
if (type < 2) {
for (int i = 0; i < m; ++i) s[i] = t[i];
} else if (type == 2) {
strcpy(s, t);
// 提示:如果此时调用 printf("%s\n", s),则本次输出结果为整个 t 字符串和换行,没有其他字符。
} else {
for (int i = 0; i < m; i += 4) {
unsigned int code = 0, pos = i;
for (int j = 1; pos < i + 4; j *= 100, ++pos) {
if (pos == m) break;
code += t[pos] * j;
}
pos = i;
while (code != 0) {
s[pos++] = code % 100;
code /= 100;
}
}
}
for (int i = 0; i < n; ++i) printf("%c", s[i]);
printf("\n");
}
输入保证 t 的长度不大于 s,两个字符串均只含大小写字母且非空,type 为 1、2 或 3。
- 输入
1 xyz abcd时,程序输出xyzd。
{{ select(1) }}
- 正确
- 错误