#2532. 2023 CSP-J1 真题 · 阅读程序2
2023 CSP-J1 真题 · 阅读程序2
2023 CSP-J1 真题(120 分钟,总分 100 分)
阅读程序2(共 6 题,共 13.5 分)
1.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int f(string x, string y) {
int m = x.size();
int n = y.size();
vector<vector<int>> v(m+1, vector<int>(n+1, 0));
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (x[i-1] == y[j-1]) {
v[i][j] = v[i-1][j-1] + 1;
} else {
v[i][j] = max(v[i-1][j], v[i][j-1]);
}
}
}
return v[m][n];
}
bool g(string x, string y) {
if (x.size() != y.size()) {
return false;
}
return f(x + x, y) == y.size();
}
int main() {
string x, y;
cin >> x >> y;
cout << g(x, y) << endl;
return 0;
}
f函数的返回值小于等于min(n,m)。
{{ select(1) }}
- 正确
- 错误
2. f函数的返回值等于两个输入字符串的最长公共子串的长度。
{{ select(2) }}
- 正确
- 错误
3. 当输入两个完全相同的字符串时,g函数的返回值总是true。
{{ select(3) }}
- 正确
- 错误
4. 将第19行中的"v[m][n]"替换为"v[n][m]",那么该程序()。
{{ select(4) }}
- 行为不变
- 只会改变输出
- 一定非正常退出
- 可能非正常退出
5. 当输入为"csp-j p-jcs"时,输出为()。
{{ select(5) }}
- "0"
- "1"
- "T"
- "F"
6. 当输入为"csppsc spsccp"时,输出为()。
{{ select(6) }}
- "T"
- "F"
- "0"
- "1"
相关
在下列比赛中: