1.vector<char>
#include<bits/stdc++.h> using namespace std; int main() { vector<char> q; char c, f; while ((c = cin.get()) != '.') { q.push_back(c); } q.push_back(c); cin >> c >> f; if (c == 'D') { for (int i = 0; i < q.size(); i++) { if (q[i] == f) { q.erase(q.begin() + i); break; } } } else if (c == 'I') { char m; cin >> m; for (int i = q.size() - 1; i >= 0; i--) { if (q[i] == f) { q.insert(q.begin() + i, m); break; } } } else if (c == 'R') { char m; cin >> m; for (int i = 0; i < q.size(); i++) { if (q[i] == f) q[i] = m; } } for (int i = 0; i < q.size(); i++) { cout << q[i]; } }
2.list<char>
#include<bits/stdc++.h> using namespace std; int main() { list<char> q; list<char>::iterator k; char c, f; while ((c = cin.get()) != '.') { q.push_back(c); } q.push_back(c); cin >> c >> f; if (c == 'D') { for (k = q.begin(); k != q.end(); k++) { if (*k == f) { k = q.erase(k); break; } } } else if (c == 'I') { char m; cin >> m; int i = 0; list<char>::iterator it; for (k = q.begin(); k != q.end(); k++) { if (*k == f) { it = k; i++; } } if (i > 0) q.insert(it, m); } else if (c == 'R') { char m; cin >> m; for (k = q.begin(); k != q.end(); k++) { if (*k == f) *k = m; } } for (k = q.begin(); k != q.end(); k++) { cout << *k; } }
0.0分
4 人评分
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:368 |
WU-蓝桥杯算法提高VIP-企业奖金发放 (C++代码)浏览:1267 |
wu-理财计划 (C++代码)浏览:907 |
求圆的面积 (C语言代码)浏览:1756 |
Cylinder (C语言描述,蓝桥杯)浏览:1279 |
sizeof的大作用 (C语言代码)浏览:1593 |
理财计划 (C语言代码)浏览:494 |
第三届阿里中间件性能挑战赛-总决赛亚军比赛攻略浏览:1170 |
C语言训练-自守数问题 (C语言代码)浏览:798 |
母牛的故事 (C语言代码)浏览:519 |