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)) != string::npos) line.erase(pos, bug.length()); cout << line << endl; } } return 0; }
--- c4.s772.cteam059.bugs.cpp.0.bugs.cpp +++ c4.s1119.cteam059.bugs.cpp.0.bugs.cpp @@ -1,5 +1,4 @@ #include <iostream> #include <string> -#include <cstdio> #include <iostream> using namespace std; @@ -7,21 +6,19 @@ int main() { - string line, bug; - int T; - unsigned pos; + string line, bug; + int T; + size_t pos; - while (scanf("%d ", &T) == 1) + while (cin >> T) { - getline(cin, bug); - for (;T;T--) + cin >> bug; + cin.ignore(); + for ( ; T; T--) { pos = 0; getline(cin, line); - while ((pos = line.find(bug), pos) != string::npos) - { + while ((pos = line.find(bug)) != string::npos) line.erase(pos, bug.length()); - pos = (bug.length()<pos) ? (0) : pos-bug.length(); - } - printf("%s\n", line.c_str()); + cout << line << endl; } }