Source code for submission s1372

Go to diff to previous submission

bugs.cpp

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <cstring>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main()
  11. {
  12. int n, len;
  13. string s;
  14. char line[2000000];
  15. char * o, * tmp;
  16. while (cin >> n >> s)
  17. {
  18. getchar();
  19. for (int i=1; i<=n; i++)
  20. {
  21. len=0;
  22. do {
  23. line[len++] = getchar();
  24. } while (line[len-1] !='\n');
  25. line[len-1] = 0;
  26. tmp = line;
  27.  
  28. while ((o = strstr(tmp, s.c_str()))) {
  29.  
  30. while (tmp < o)
  31. {
  32. printf("%c", tmp[0]);
  33. tmp++;
  34. }
  35. tmp += s.length();
  36. };
  37. while (tmp < line+len)
  38. {
  39. printf("%c", tmp[0]);
  40. tmp++;
  41. }
  42. printf("\n");
  43. }
  44. }
  45.  
  46. return 0;
  47. }
  48.  

Diff to submission s1249

bugs.cpp

--- c4.s1249.cteam045.bugs.cpp.0.bugs.cpp
+++ c4.s1372.cteam045.bugs.cpp.0.bugs.cpp
@@ -10,8 +10,8 @@
 int main()
 {
-        int n, len, ii;
+        int n, len;
         string s;
         char line[2000000];
-        char * o;
+        char * o, * tmp;
         while (cin >> n >> s)
         {
@@ -19,20 +19,26 @@
                 for (int i=1; i<=n; i++)
                 {
-                        ii=0;
+                        len=0;
                         do {
-                                line[ii++] = getchar();
-                        } while (line[ii-1] !='\n');
-                        line[ii-1] = 0;
-                        len = ii;
-                        while ((o = strstr(line, s.c_str()))) {
-                                while (o < line+len-1)
+                                line[len++] = getchar();
+                        } while (line[len-1] !='\n');
+                        line[len-1] = 0;
+                        tmp = line;
+
+                        while ((o = strstr(tmp, s.c_str()))) {
+
+                                while (tmp < o)
                                 {
-                                        o++;
-                                        o[-1] = o[s.length()-1];
+                                        printf("%c", tmp[0]);
+                                        tmp++;
                                 }
-                                o[0] = 0;
-                                len -= s.length();
+                                tmp += s.length();
                         };
-                        cout << line << endl;
+                        while (tmp < line+len)
+                        {
+                                printf("%c", tmp[0]);
+                                tmp++;
+                        }
+                        printf("\n");
                 }
         }