1 #include <cstdio> 2 #include <cstring> 3 using namespace std; 4 char st[100]; 5 int main() { 6 scanf("%s", st); 7 int n = strlen(st); 8 for (int i = 1; i <= n; ++i) { 9 if (n % i == 0) { 10 char c = st[i - 1]; 11 if (c >= 'a') 12 st[i - 1] = c - 'a' + 'A'; 13 } 14 } 15 printf("%s", st); 16 return 0; 17 }
输入的字符串只能由小写字母或大写字母组成。( )
(1.5 分)若将第 行的 i = 1 改为 i = 0,程序运行时会发生错误。( )
若将第 行的 i <= n 改为 i * i <= n,程序运行结果不会改变。( )
若输入的字符串全部由大写字母组成,那么输出的字符串就跟输入的字符串一样。( )
(1.5 分)若输入的字符串长度为 ,那么输入的字符串跟输出的字符串相比,至多有( )个字符不同。
(3 分)若输入的字符串长度为( ),那么输入的字符串跟输出的字符串相比,至多有 个字符不同。
(3 分)1 #include <cstdlib> 2 #include <iostream> 3 using namespace std; 4 5 char encoder[26] = {'C', 'S', 'P', 0}; 6 char decoder[26]; 7 8 string st; 9 10 int main() { 11 int k = 0; 12 for (int i = 0; i < 26; ++i) 13 if (encoder[i] != 0) ++k; 14 for (char x = 'A'; x <= 'Z'; ++x) { 15 bool flag = true; 16 for (int i = 0; i < 26; ++i) 17 if (encoder[i] == x) { 18 flag = false; 19 break; 20 } 21 if (flag) { 22 encoder[k] = x; 23 ++k; 24 } 25 } 26 for (int i = 0; i < 26; ++i) 27 decoder[encoder[i] - 'A'] = i + 'A'; 28 cin >> st; 29 for (int i = 0; i < st.length(); ++i) 30 st[i] = decoder[st[i] - 'A']; 31 cout << st; 32 return 0; 33 }
输入的字符串应当只由大写字母组成,否则在访问数组时可能越界。( )
(1.5 分)若输入的字符串不是空串,则输入的字符串与输出的字符串一定不一样。( )
(1.5 分)将第 行的 i < 26 改为 i < 16,程序运行结果不会改变。( )
将第 行的 i < 26 改为 i < 16,程序运行结果不会改变。( )
若输出的字符串为 ABCABCABCA,则下列说法正确的是( )。
若输出的字符串为 CSPCSPCSPCSP,则下列说法正确的是( )。
1 #include <iostream> 2 using namespace std; 3 4 int n; 5 int a[1000]; 6 7 int f(int x) 8 { 9 int ret = 0; 10 for (; x; x &= x - 1) ret++; 11 return ret; 12 } 13 14 int g(int x) 15 { 16 return x & -x; 17 } 18 19 int main() 20 { 21 cin >> n; 22 for (int i = 0; i < n; i++) cin >> a[i]; 23 for (int i = 0; i < n; i++) 24 cout << f(a[i]) + g(a[i]) << ' '; 25 cout << endl; 26 return 0; 27 }
输入的 n 等于 时,程序不会发生下标越界。( )
输入的 a[i] 必须全为正整数,否则程序将陷入死循环。( )
当输入为 5 2 11 9 16 10 时,输出为 3 4 3 17 5。( )
当输入为 1 511998 时,输出为 18。( )
将源代码中 g 函数的定义(- 行)移到 main 函数的后面,程序可以正常编译运行。( )
当输入为 2 -65536 2147483647 时,输出为( )。
1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 5 double f(double a, double b, double c) { 6 double s = (a + b + c) / 2; 7 return sqrt(s * (s - a) * (s - b) * (s - c)); 8 } 9 10 int main() { 11 cout.flags(ios::fixed); 12 cout.precision(4); 13 14 int a, b, c; 15 cin >> a >> b >> c; 16 cout << f(a, b, c) << endl; 17 return 0; 18 }
当输入为 2 2 2 时,输出为 1.7321。( )
将第 行中的 (s - b) * (s - c) 改为 (s - c) * (s - b) 不会影响程序运行的结果。( )
程序总是输出四位小数。( )
(2 分)当输入为 3 4 5时,输出为( )。
当输入为 5 12 13时,输出为( )。
1 #include <cstdio> 2 using namespace std; 3 int n, m; 4 int a[100], b[100]; 5 6 int main() { 7 scanf("%d%d", &n, &m); 8 for (int i = 1; i <= n; ++i) 9 a[i] = b[i] = 0; 10 for (int i = 1; i <= m; ++i) { 11 int x, y; 12 scanf("%d%d", &x, &y); 13 if (a[x] < y && b[y] < x) { 14 if (a[x] > 0) 15 b[a[x]] = 0; 16 if (b[y] > 0) 17 a[b[y]] = 0; 18 a[x] = y; 19 b[y] = x; 20 } 21 } 22 int ans = 0; 23 for (int i = 1; i <= n; ++i) { 24 if (a[i] == 0) 25 ++ans; 26 if (b[i] == 0) 27 ++ans; 28 } 29 printf("%d\n",ans); 30 return 0; 31 }
假设输入的 和 都是正整数, 和 都是在 范围内的整数,完成下面的判断题和单选题。
当 时,输出的值一定小于 。( )
(1.5 分)执行完第 行的 ++ans 时,ans 一定是偶数。( )
a[i] 和 b[i] 不可能同时大于 。( )
若程序执行到第 行时,x 总是小于 y,那么第 行不会被执行。( )
若 个 x 两两不同,且 个 y 两两不同,则输出的值为( )。
若 个 x 两两不同,且 个 y 都相等,则输出的值为( )。
1 #include <iostream> 2 #include <string> 3 using namespace std; 4 5 char base[64]; 6 char table[256]; 7 8 void init() 9 { 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.5 分)输出的第一行为 -1。( )
设输入字符串长度为 n,decode 函数的时间复杂度为( )。
当输入为 Y3Nx 时,输出的第二行为( )。
当输入为 Y2NmIDIwMjE= 时,输出的第二行为( )。
1 #include <iostream> 2 using namespace std; 3 4 bool isPrime(int n) { 5 if (n <= 1) { 6 return false; 7 } 8 for (int i = 2; i * i <= n; i++) { 9 if (n % i == 0) { 10 return false; 11 } 12 } 13 return true; 14 } 15 16 int countPrimes(int n) { 17 int count = 0; 18 for (int i = 2; i <= n; i++) { 19 if (isPrime(i)) { 20 count++; 21 } 22 } 23 return count; 24 } 25 26 int sumPrimes(int n) { 27 int sum = 0; 28 for (int i = 2; i <= n; i++) { 29 if (isPrime(i)) { 30 sum += i; 31 } 32 } 33 return sum; 34 } 35 36 int main() { 37 int x; 38 cin >> x; 39 cout << countPrimes(x) << " " << sumPrimes(x) << endl; 40 return 0; 41 }
当输入为 10 时,程序的第一个输出为 4,第二个输出为 17。( )
若将 isPrime(i) 函数中的条件改为 i <= n / 2,输入 20 时,countPrimes(20) 的输出将变为 6。( )
sumPrimes 函数计算的是从 到 之间的所有素数之和。( )
当输入为 50 时,sumPrimes(50) 的输出为( )。
如果将 for (int i = 2; i * i <= n; i++) 改为 for (int i = 2; i <= n; i++),输入 10 时,程序的输出( )。
1 #include <iostream> 2 #include <cmath> 3 using namespace std; 4 5 int customFunction(int a, int b) { 6 if (b == 0) { 7 return a; 8 } 9 return a + customFunction(a, b-1); 10 } 11 12 int main() { 13 int x, y; 14 cin >> x >> y; 15 int result = customFunction(x, y); 16 cout << pow(result, 2) << endl; 17 return 0; 18 }
当输入为 2 3 时,customFunction(2, 3) 的返回值为 64。( )
当 b 为负数时,customFunction(a, b) 会陷入无限递归。( )
当 b 的值越大,程序的运行时间越长。( )
当输入为 5 4 时,customFunction(5, 4) 的返回值为( )。
如果输入 和 ,则程序的最终输出为( )。
(3 分)若将 customFunction 函数改为 return a + customFunction(a-1, b-1);,并输入 3 3,则程序的最终输出为( )。
1 #include <algorithm> 2 #include <cstdio> 3 #include <cstring> 4 inline int gcd(int a, int b) { 5 if (b == 0) 6 return a; 7 return gcd(b, a % b); 8 } 9 int main() { 10 int n; 11 scanf("%d", &n); 12 int ans = 0; 13 for (int i = 1; i <= n; ++i) { 14 for (int j = i + 1; j <= n; ++j) { 15 for (int k = j + 1; k <= n; ++k) { 16 if (gcd(i, j) == 1 && gcd(j, k) == 1 17 && gcd(i, k) == 1) { 18 ++ans; 19 } 20 } 21 } 22 } 23 printf("%d\n", ans); 24 return 0; 25 }
当输入为 2 时,程序并不会执行第 行的判断语句。( )
将第 行中的 && gcd(i,k)==1 删去不会影响程序运行结果。
当输入的 的时候,程序总是输出一个正整数。
(1.5 分)将第 行的 gcd(b,a%b) 改为 gcd(a,a%b) 后,程序可能出现的问题是( )
当输入为 8 的时候,输出为
调用 gcd(36,42) 会返回
1 #include <iostream> 2 using namespace std; 3 const int maxn = 10000; 4 int n; 5 int a[maxn]; 6 int b[maxn]; 7 int f(int l, int r, int depth) { 8 if (l > r) 9 return 0; 10 int min = maxn, mink; 11 for (int i = l; i <= r; ++i) { 12 if (min > a[i]) { 13 min = a[i]; 14 mink = i; 15 } 16 } 17 int lres = f(l, mink - 1, depth + 1); 18 int rres = f(mink + 1, r, depth + 1); 19 return lres + rres + depth * b[mink]; 20 } 21 int main() { 22 cin >> n; 23 for (int i = 0; i < n; ++i) 24 cin >> a[i]; 25 for (int i = 0; i < n; ++i) 26 cin >> b[i]; 27 cout << f(0, n - 1, 1) << endl; 28 return 0; 29 }
如果 a 数组有重复的数字,则程序运行时会发生错误。( )
如果 b 数组全为 ,则输出为 。( )
当 时,最坏情况下,与第 行的比较运算执行的次数最接近的是( )。
(3 分)当 时,最好情况下,与第 行的比较运算执行的次数最接近的是( )。
(3 分)当 时,若 b 数组满足对任意 都有 b[i] = i + 1,那么输出最大为( )。
当 时,若 b 数组满足对任意 都有 b[i] = 1,那么输出最小为( )。
1 #include <iostream> 2 using namespace std; 3 4 long long n, ans; 5 int k, len; 6 long long d[1000000]; 7 8 int main() { 9 cin >> n >> k; 10 d[0] = 0; 11 len = 1; 12 ans = 0; 13 for (long long i = 0; i < n; ++i) { 14 ++d[0]; 15 for (int j = 0; j + 1 < len; ++j) { 16 if (d[j] == k) { 17 d[j] = 0; 18 d[j + 1] += 1; 19 ++ans; 20 } 21 } 22 if (d[len - 1] == k) { 23 d[len - 1] = 0; 24 d[len] = 1; 25 ++len; 26 ++ans; 27 } 28 } 29 cout << ans << endl; 30 return 0; 31 }
假设输入的 是不超过 的正整数, 都是不超过 的正整数,完成下面的判断题和单选题。
若 ,则输出 ans 时,len=n。( )
若 ,则输出 ans 时,len 一定小于 。( )
若 ,则输出 ans 时, 一定大于 。( )
若输入的 等于 、 为 ,则输出等于( )。
(3 分)若输入的 等于 (即 )、 为 ,则输出等于( )。
(3 分)若输入的 等于 、 为 ,则输出等于( )。
(3 分)