Go to diff to previous submission
#include <iostream> #include <string> #include <cstdio> #include <iostream> using namespace std; int main() { string line, bug; int T; unsigned pos; while (scanf("%d ", &T) == 1) { getline(cin, bug); for (;T;T--) { pos = 0; getline(cin, line); while ((pos = line.find(bug), pos) != string::npos) { line.erase(pos, bug.length()); pos = (bug.length()<pos) ? (0) : pos-bug.length(); } printf("%s\n", line.c_str()); } } return 0; }
--- c4.s564.cteam059.bugs.cpp.0.bugs.cpp +++ c4.s772.cteam059.bugs.cpp.0.bugs.cpp @@ -16,7 +16,11 @@ for (;T;T--) { + 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 = (bug.length()<pos) ? (0) : pos-bug.length(); + } printf("%s\n", line.c_str()); }