#45896: C++ 嘿嘿嘿嘿嘿


1121228@stu.wghs.tp.edu.tw (你知道我是誰嗎!!??)

學校 : 臺北市立建國高級中學
編號 : 266561
來源 : [60.248.154.139]
最後登入時間 :
2025-05-14 12:52:11
b772. 50010. Word Editor -- NTU批改娘計算機程式設計課程 | From: [60.248.154.139] | 發表日期 : 2025-04-25 13:03

#include <iostream>
#include <string>
using namespace std;

int main() {
    string s, command;
    cin >> s;
    bool valid = true;

    while (cin >> command) {
        if (command == "replace") {
            char a, b;
            cin >> a >> b;
            for (int i = 0; i < s.length(); i++) {
                if (s[i] == a) s[i] = b;
            }
        } else if (command == "remove") {
            char a;
            cin >> a;
            for (int i = 0; i < s.length();) {
                if (s[i] == a) s.erase(i, 1);
                else i++;
            }
        } else if (command == "addhead") {
            char a;
            cin >> a;
            s.insert(0, 1, a);
        } else if (command == "addtail") {
            char a;
            cin >> a;
            s.push_back(a);
        } else if (command == "end") {
            break;
        } else {
            cout << "invalid command " << command << endl;
            valid = false;
            break;
        }
    }

    if (valid) {
        cout << s << endl;
    }
    return 0;
}

 
ZeroJudge Forum