Tsinsen A1102 字符串编辑

http://oj.tsinsen.com/A1102

分析(?):简单模拟,水得可以

代码:

#include "bits/stdc++.h"
using namespace std;

int main () {
    string s;
    getline(cin, s);
    char cmd, s1, s2;
    cin >> cmd;
    switch (cmd) {
        case 'D':
            cin >> s1;
            s.erase(s.find_first_of(s1), 1);
            cout << s;
            break;
        case 'I':
            cin >> s1 >> s2;
            s.insert(s.begin() + s.find_last_of(s1), s2);
            cout << s;
            break;
        case 'R':
            cin >> s1 >> s2;
            int len = s.size();
            for (int i = 0; i < len; ++i)
                if (s[i] != s1) cout << s[i];
                else cout << s2;
            break;
    }
    return 0;
}

你可能感兴趣的:(ACM-01)