Go to diff to previous submission
#include <iostream> #include <string> #include <iostream> using namespace std; int main() { string line, bug; int T; size_t pos; while (cin >> T) { cin >> bug; cin.ignore(); for ( ; T; T--) { pos = 0; getline(cin, line); while ((pos = line.find(bug, pos)) != string::npos) { line.erase(pos, bug.length()); pos = pos - bug.length(); pos = (pos < 0) ? 0 : pos; } cout << line << endl; } } return 0; }
--- c4.s1119.cteam059.bugs.cpp.0.bugs.cpp +++ c4.s1126.cteam059.bugs.cpp.0.bugs.cpp @@ -18,6 +18,10 @@ pos = 0; getline(cin, line); - while ((pos = line.find(bug)) != string::npos) + while ((pos = line.find(bug, pos)) != string::npos) + { line.erase(pos, bug.length()); + pos = pos - bug.length(); + pos = (pos < 0) ? 0 : pos; + } cout << line << endl; }