Source code for submission s907

Go to diff to previous submission

bugs.cpp

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cassert>
  4. #include <vector>
  5. #include <stack>
  6. #include <cstdio>
  7. #include <deque>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. while(true)
  14. {
  15. int T;
  16. string bug, t;
  17. cin >> T >> bug;
  18. getline(cin, t);
  19. if(!cin) break;
  20. deque<int> a;
  21. for(int i=0; i<T; ++i)
  22. {
  23. char c;
  24. int current=0;
  25. while((c=getchar()) !='\n')
  26. {
  27. if(c==bug[current])
  28. {
  29. current++;
  30. if(current >= bug.size())
  31. {
  32. if(a.empty())
  33. {
  34. current=0;
  35. }
  36. else
  37. {
  38. current = a.back(); a.pop_back();
  39. }
  40. }
  41. }
  42. else if(c==bug[0])
  43. {
  44. a.push_back(current);
  45. current = 1;
  46. }
  47. else
  48. {
  49. for(deque<int>::iterator cr=a.begin(); cr!=a.end(); ++cr)
  50. {
  51. cout << bug.substr(0, *cr);
  52. }
  53. cout << bug.substr(0,current);
  54. a.clear();
  55. putchar(c);
  56. current = 0;
  57. }
  58. }
  59. for(deque<int>::iterator cr=a.begin(); cr!=a.end(); ++cr)
  60. {
  61. cout << bug.substr(0, *cr);
  62. }
  63. cout << bug.substr(0,current);
  64. a.clear();
  65. putchar(c);
  66. current = 0;
  67. //putchar('\n');
  68. }
  69. }
  70. return 0;
  71. }
  72.  
  73.  

Diff to submission s739

bugs.cpp

--- c4.s739.cteam038.bugs.cpp.0.bugs.cpp
+++ c4.s907.cteam038.bugs.cpp.0.bugs.cpp
@@ -63,7 +63,7 @@
                         cout << bug.substr(0,current);
                         a.clear();
-                                                putchar(c);
-                                                current = 0;
-                        putchar('\n');
+                        putchar(c);
+                        current = 0;
+                        //putchar('\n');
                 }
         }