Source code for submission s1240

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. char bugc[1001];
  17. if(scanf("%d %s\n", &T, bugc)!=2) break;
  18. string bug(bugc);
  19. deque<int> a;
  20. for(int i=0; i<T; ++i)
  21. {
  22. char c;
  23. int current=0;
  24. while((c=getchar()) !='\n')
  25. {
  26. if(c==bug[current])
  27. {
  28. current++;
  29. if(current >= bug.size())
  30. {
  31. if(a.empty())
  32. {
  33. current=0;
  34. }
  35. else
  36. {
  37. current = a.back(); a.pop_back();
  38. }
  39. }
  40. }
  41. else if(c==bug[0])
  42. {
  43. a.push_back(current);
  44. current = 1;
  45. }
  46. else
  47. {
  48. for(deque<int>::iterator cr=a.begin(); cr!=a.end(); ++cr)
  49. {
  50. cout << bug.substr(0, *cr);
  51. }
  52. cout << bug.substr(0,current);
  53. a.clear();
  54. putchar(c);
  55. current = 0;
  56. }
  57. }
  58. for(deque<int>::iterator cr=a.begin(); cr!=a.end(); ++cr)
  59. {
  60. cout << bug.substr(0, *cr);
  61. }
  62. cout << bug.substr(0,current);
  63. a.clear();
  64. putchar(c);
  65. current = 0;
  66. //putchar('\n');
  67. }
  68. }
  69. return 0;
  70. }
  71.  
  72.  

Diff to submission s1208

bugs.cpp

--- c4.s1208.cteam038.bugs.cpp.0.bugs.cpp
+++ c4.s1240.cteam038.bugs.cpp.0.bugs.cpp
@@ -14,8 +14,7 @@
         {
                 int T;
-                string bug, t;
-                cin >> T >> bug;
-                getline(cin, t);
-                if(!cin) break;
+                char bugc[1001];
+                if(scanf("%d %s\n", &T, bugc)!=2) break;
+                string bug(bugc);
                 deque<int> a;
                 for(int i=0; i<T; ++i)