Source code for submission s772

Go to diff to previous submission

bugs.cpp

  1. #include <iostream>
  2. #include <string>
  3. #include <cstdio>
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. string line, bug;
  10. int T;
  11. unsigned pos;
  12.  
  13. while (scanf("%d ", &T) == 1)
  14. {
  15. getline(cin, bug);
  16. for (;T;T--)
  17. {
  18. pos = 0;
  19. getline(cin, line);
  20. while ((pos = line.find(bug), pos) != string::npos)
  21. {
  22. line.erase(pos, bug.length());
  23. pos = (bug.length()<pos) ? (0) : pos-bug.length();
  24. }
  25. printf("%s\n", line.c_str());
  26. }
  27. }
  28.  
  29. return 0;
  30. }
  31.  

Diff to submission s564

bugs.cpp

--- 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());
                 }