解题思路:
用string类即可,最后全替换就for循环一下吧~
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; int main() { int pos; char a, b; string s, cmd; getline(cin, s); cin >> cmd; if (cmd == "D") { cin >> a; pos = s.find(a); if (pos == string::npos) { cout << "NOT Found." << endl; } else { s.erase(pos, 1); cout << s << endl; } } else if (cmd == "I") { cin >> a >> b; pos = s.rfind(a); if (pos == string::npos) { cout << "NOT Found." << endl; } else { s.insert(pos, 1, b); cout << s << endl; } } else if (cmd == "R") { cin >> a >> b; pos = s.find(a); if (pos == string::npos) { cout << "NOT Found." << endl; } else { for (int i = pos; i < s.length(); ++i) { if (s[i] == a) s[i] = b; } cout << s << endl; } } return 0; }
0.0分
0 人评分
点我有惊喜!你懂得!浏览:1395 |
C二级辅导-等差数列 (C语言代码)浏览:591 |
川哥的吩咐 (C语言代码)浏览:875 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:629 |
C语言程序设计教程(第三版)课后习题8.2 (Java代码)浏览:2269 |
C语言考试练习题_一元二次方程 (C语言代码)浏览:737 |
蓝桥杯历届试题-九宫重排 (C++代码)浏览:2784 |
【出圈】 (C语言代码)浏览:558 |
母牛的故事 (C语言代码)浏览:435 |
Pascal三角 (C语言代码)格式错误浏览:521 |