#45893: C++ 也有replace函式喔!!(不是只有python)


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

學校 : 臺北市私立薇閣高級中學
編號 : 266561
來源 : [60.248.154.139]
最後登入時間 :
2025-08-21 12:45:57

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, names;
    getline(cin, s);
    getline(cin, names);
    size_t pos = 0;
    while ((pos = names.find(s, pos)) != string::npos) {
        names.replace(pos, s.length(), "\n");
        pos += 1;
    }
    cout << names;

    return 0;
}