2025年3月CCF—GESP(C++三级)编程能力等级认证试卷
三级
2025
2025-06-28 10:10:48
77次
一、单选题
以下代码的功能是将数组中的奇数和偶数分别放在数组的前半部分和后半部分,横线处应该填入的是()
#include <iostream>
using namespace std;
int main() {
int arr[] = {1, 2, 3, 4, 5};
int left = 0, right = 4;
while (left < right) {
while (arr[left] % 2 == 1 && left < right) left++;
______________________________________________________
if (left < right) {
swap(arr[left], arr[right]);
}
}
for (int i = 0; i < 5; i++) {
cout << arr[i] << " ";
}
return 0;
} | A. while (arr[left] % 2 == 0 && left < right) right--; |
B. while (arr[right] % 2 == 0 && left < right) left--; |
| C. while (arr[right] % 2 != 0 && left < right) right--; |
D. while (arr[right] % 2 == 0 && left < right) right--; |
【知识点】 CCF—GESP C++三级
以下代码的说法正确的是什么( )
#include <iostream>
using namespace std;
int main() {
int a = 0b1101;
int b = 0b1011;
cout << (a ^ b);
return 0;
} | A. if (arr[maxIndex] > arr[i]) |
B. if (arr[i]-1 > arr[maxIndex]) |
| C. if (arr[i]+1 > arr[maxIndex]) |
D. if (arr[i] > arr[maxIndex]) |
【知识点】 CCF—GESP C++三级
有 n 个正整数,假设—个正整数是美丽数字当且仅当该正整数是 9 的倍数但不是 8 的倍数。下面的程序 是 编写计算 n 个正整数中美丽数字的数量,横线处应该填入的是()
for (int i = 1; i <= n; i++) {
cin >> a;
__________________
cnt++;
} | A. if (a % 9 != 0 && a % 8 != 0) |
B. if (a % 9 == 0 & a % 8 == 0) |
| C. if (a % 9 == 0 & a % 8 != 0) |
D. if (a % 9 == 0 & a % 8 != 0) |
【知识点】 CCF—GESP C++三级
想要得到字符串 world ,下面程序横线处应该填入的是()
#include <iostream>
#include <string>
using namespace std; int main() {
string str = "HelloC++";
__________________
__________________
return 0;
} | A. str.insert(4, "World"); cout << str.substr(4, 4); |
B. cout << str.substr(5, 5); |
| C. str.insert("World"); cout << str.substr(5, 5); |
D. str.insert(5, "World"); cout << str.substr(5, 5); |
【知识点】 CCF—GESP C++三级
下面枚举法查找最大值索引程序中,横线处应该填写的是()
#include <iostream>
using namespace std;
int main() {
int arr[] = {3, 7, 2, 9, 5};
int maxIndex = 0;
for (int i = 1; i < 5; i++) {
__________________
{
maxIndex = i;
}
}
cout << maxIndex;
return 0;
} | A. if (arr[maxIndex] > arr[i]) |
B. if (arr[i]-1 > arr[maxIndex]) |
| C. if (arr[i]+1 > arr[maxIndex]) |
D. if (arr[i] > arr[maxIndex]) |
【知识点】 CCF—GESP C++三级
二、判断题
三、编程题
词频统计
题目描述
在文本处理中,统计单词出现的频率是—个常见的任务。现在,给定 n 个单词,你需要找出其中出现次数最多的 单词。在本题中, 忽略单词中字母的大小写(即 Apple 、 apple 、 APPLE 、 aPPle 等均视为同—个单词)。
请你编写—个程序,输入 n 个单词,输出其中出现次数最多的单词。
输入格式
第 1 行:—个整数 n ,表示单词的个数。
接下来 n 行:每行包含—个单词,单词由大小写英文字母组成。
输入保证,出现次数最多的单词只会有一个。
输出格式
输出—行,包含出现次数最多的单词(输出单词为小写形式)。
输入样例
6 Apple banana apple Orange banana apple
输出样例
apple
数据范围
对于所有测试点, 1 ≤ n ≤ 100 ,每个单词的长度不超过 30 ,且仅由大小写英文字母组成。
【知识点】 CCF—GESP C++三级
2025
题目描述
小 A 有—个整数 x ,他想找到最小的正整数 y 使得下式成立:
(x and y) + (x or y)= 2025
其中 and 表示二进制按位与运算,or 表示二进制按位或运算。如果不存在满足条件的 y ,则输出 -1 。
输入格式
—行, —个整数 x 。
输出格式
—行, —个整数,若满足条件的 y 存在则输出 y ,否则输出 -1 。
输入样例
1025
输出样例
1000
数据范围
对于所有测试点,保证 0 ≤ x < 2025。
提示
(x and y) +(x or y) = 2025
其中:
. and 表示按位与运算,运算符为 & 。
. or 表示按位或运算,运算符为 | 。
【知识点】 CCF—GESP C++三级
