Source code for submission s1119

Go to diff to previous submission

bugs.cpp

  1. #include <iostream>
  2. #include <string>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string line, bug;
  9. int T;
  10. size_t pos;
  11.  
  12. while (cin >> T)
  13. {
  14. cin >> bug;
  15. cin.ignore();
  16. for ( ; T; T--)
  17. {
  18. pos = 0;
  19. getline(cin, line);
  20. while ((pos = line.find(bug)) != string::npos)
  21. line.erase(pos, bug.length());
  22. cout << line << endl;
  23. }
  24. }
  25.  
  26. return 0;
  27. }
  28.  

Diff to submission s772

bugs.cpp

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