Files
ClassFeedback/output/CSP03-第8课-课前默写-string(一)复习.md
chengzi 68a43eb4af 更新第8周课评与学生档案:新增多班级学生画像及课评汇总归档
- 补全CSP03周六0830/1400班学生课评汇总与profile档案
- 新增AI03周六1900、周日0845/1400、CSP03周日1030、K4周日1900班级结构
- 更新K4周五1900班课评汇总
- 优化课评生成技能规则
- 更新.gitignore与教学输出文档
2026-04-25 20:44:49 +08:00

101 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# CSP03班 第8课 课前默写10分钟
## 一、填空题(每空 4 分,共 32 分)
1. 声明一个 `string` 变量 `s` 并初始化为 `"hello"` 的语句是:
`string s = _______________ ;`
2. 获取字符串 `s` 长度的函数是 `s._______()`
3. 读取一整行字符串(**包含空格**)应该使用函数:
`_______________(cin, s);`
4. `cin >> s` 读取字符串时,遇到 **_______** 就会停止读取。
5. 在字符串 `s` 中查找子串 `"abc"`,应该调用:
`s._______________("abc")`
6. 如果 `find()` 函数没有找到目标子串,返回值是 **_______**
7. 字符串 `"abcdef"` 中,字符 `'c'` 的下标是 **_______**
8. 从字符串 `s` 的下标 `2` 开始截取 `3` 个字符,应写成:
`s._______________(2, 3)`
---
## 二、判断题(每题 4 分,共 16 分)
正确的打 `√`,错误的打 `×`
1. `string s = "abc"; s += "def";` 执行后,`s` 的值是 `"abcdef"`
2. `string::npos` 的值等于 `-1`
3. )两个 `string` 可以直接用 `==` 比较是否相等。
4. `getline(cin, s)` 可以读取包含空格的整行字符串,直到遇到回车。
---
## 三、代码填空(每空 4 分,共 24 分)
下面程序的功能是:输入一行字符串,统计其中**大写字母**的数量。请补全代码。
```cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string s;
_______________(cin, s); // ① 读入一整行
int cnt = 0;
for (int i = 0; i < s.___________(); i++) { // ② 遍历字符串
if (_______(s[i])) { // ③ 判断是否为大写字母
cnt++;
}
}
cout << cnt << endl;
return 0;
}
```
---
## 四、代码阅读(共 10 分)
阅读以下程序,写出输出结果:
```cpp
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "hello world";
cout << s.find("world") << endl; // 输出①________
if (s.find("xyz") == string::npos) {
cout << "YES" << endl; // 输出②________
} else {
cout << "NO" << endl;
}
return 0;
}
```
---
## 五、简答题(共 30 分)
1. **简述 `cin >> s` 和 `getline(cin, s)` 在读取字符串时的主要区别。**30分
答:
_________________________________________________________________
_________________________________________________________________
---
*穹狼科创 · CSP03班 · 2026春季*