1 条题解
-
0
【例68.1】自动应答器
解题思路
将输入名字插入固定句式“Hi, 名字. What's the matter?”,其余字符原样输出。
正确性说明
依题目给出的对应关系逐项处理,位置与原输入保持明确对应。每一步完成当前项的全部贡献,结束后得到所有位置或字符的目标结果。
易错点
逗号后一个空格,名字后句点和一个空格;保留撇号。
复杂度
时间O(L),空间O(L)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; cout << "Hi, " << s << ". What's the matter?\n"; return 0; }
- 1