Source code for submission s1006

Go to diff to previous submission

bugs.cpp

  1. #include <string>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int T;
  7. string bugText;
  8. int lineEnds;
  9.  
  10. bool bugComplete(string text)
  11. {
  12. if (text.size() != bugText.size())
  13. return false;
  14.  
  15. int i = text.size() -1;
  16. return text[i] == bugText[i];
  17. //return text == bugText;
  18. }
  19.  
  20. bool bugStart(char ch)
  21. {
  22. if (ch == bugText[0])
  23. return true;
  24.  
  25. return false;
  26. }
  27.  
  28. bool bugFailed(string text)
  29. {
  30. if (text.size() > bugText.size())
  31. return true;
  32.  
  33. int i = text.size() -1;
  34. return text[i] != bugText[i];
  35.  
  36. /* for (int i = text.size() -1 ; i >= 0; --i)
  37.   {
  38.   if (text[i] != bugText[i])
  39.   return true;
  40.   }*/
  41.  
  42. return false;
  43. }
  44.  
  45. string readBug()
  46. {
  47. string text;
  48. while (lineEnds < T)
  49. {
  50. char ch;
  51. ch = cin.get();
  52. if (ch == '\n')
  53. {
  54. //cout << "endl" << endl;
  55. lineEnds++;
  56. text += ch;
  57. continue;
  58. }
  59.  
  60. if (bugStart(ch))
  61. {
  62. //cout << "bugstart" << endl;
  63. if (text.empty())
  64. text += ch;
  65. else
  66. {
  67. cin.unget();
  68. text += readBug();
  69. }
  70. }
  71. else
  72. {
  73. //cout << "check bug" << endl;
  74. text += ch;
  75.  
  76. if (bugComplete(text))
  77. {
  78. //cout << "bug complete!!" << endl;
  79. return "";
  80. }
  81.  
  82. if (bugFailed(text))
  83. return text;
  84. }
  85.  
  86. }
  87. return text;
  88. }
  89.  
  90. string baseLoop()
  91. {
  92. string text;
  93. while (lineEnds < T)
  94. {
  95. char ch;
  96. ch = cin.get();
  97.  
  98. if (ch == '\n')
  99. {
  100. // cout << "endl" << endl;
  101. lineEnds++;
  102. text += ch;
  103. continue;
  104. }
  105.  
  106. if (bugStart(ch))
  107. {
  108. //cout << "bugstart" << endl;
  109. cin.unget();
  110. text += readBug();
  111. }
  112. else
  113. text += ch;
  114. }
  115.  
  116. return text;
  117. }
  118.  
  119. int main()
  120. {
  121.  
  122. while (true)
  123. {
  124. cin >> T;
  125. cin >> bugText;
  126. if (!cin.good())
  127. {
  128. break;
  129. }
  130.  
  131. lineEnds = 0;
  132. char ch;
  133. ch = cin.get();
  134. if (ch != '\n')
  135. cin.unget();
  136. cout << baseLoop() << endl;
  137. }
  138.  
  139. }

Diff to submission s995

bugs.cpp

--- c4.s995.cteam054.bugs.cpp.0.bugs.cpp
+++ c4.s1006.cteam054.bugs.cpp.0.bugs.cpp
@@ -31,9 +31,12 @@
       return true;
     
-    for (int i = text.size() -1 ; i >= 0; --i)
+    int i = text.size() -1;
+    return text[i] != bugText[i];
+    
+   /* for (int i = text.size() -1 ; i >= 0; --i)
     {
         if (text[i] != bugText[i])
           return true;
-    }
+    }*/
     
     return false;