C++ 文字列 一括置換

// https://www.sejuku.net/blog/54493
// を少し書き換えたもの
// 参照なので書き換えます
string replace_all(string &s, string from, string to) {
    ll pos = s.find(from);
    while(1){
      pos = s.find(from, pos);
      if(pos==string::npos) break;
      s.replace(pos, from.length(), to);
      pos += to.length();
    }
    return s;
}

使い方

s = replace_all(s, "ABC", "B");

verified

http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=4008789#1

プログラミングコンテストチャレンジブック [第2版] ?問題解決のアルゴリズム活用力とコーディングテクニックを鍛える?

プログラミングコンテストチャレンジブック [第2版] ?問題解決のアルゴリズム活用力とコーディングテクニックを鍛える?