Source code for submission s1383

Go to diff to previous submission

bugs.cpp

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <vector>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. int main ( )
  9. {
  10. int lines;
  11. string expr;
  12. while ( cin >> lines >> expr ) {
  13.  
  14. cin . get();
  15. int exprL = ( int ) expr . length();
  16. int array[ 2000001 ];
  17. if ( ! lines ) cout << endl;
  18. while ( lines-- )
  19. {
  20. int cnt = 0;
  21. char ch;
  22. //start = end = array;
  23. //getline( cin, line );
  24. int curr = 0;
  25. //memset( array, 0, sizeof( array ) );
  26. while ( (ch = cin.get()) != '\n' )
  27. {
  28. if ( ! cin . good() )
  29. {
  30. ch = '\0';
  31. break;
  32. }
  33. if(ch == expr[curr] && curr > 0) curr++;
  34. else if(ch == expr[0]) {
  35. if(curr > 0) array[cnt++] = curr;
  36. curr = 1;
  37. }
  38. else {
  39. if(cnt > 0) {
  40. for(int i = 0; i < cnt; i++) cout << expr.substr(0, array[i]);
  41. cnt = 0;
  42. }//vypiš zásobník
  43. if(curr > 0) {
  44. cout << expr.substr(0, curr);
  45. }//vypiš current
  46. cout << ch;
  47. cnt = 0;
  48. curr = 0;
  49. }
  50.  
  51. if ( curr == exprL ) {
  52. if(cnt > 0) curr = array[--cnt];
  53. else curr = 0;
  54. }//načti předchozí ze zásobníku
  55.  
  56.  
  57. }
  58. if(cnt > 0) {
  59. for(int i = 0; i < cnt; i++) cout << expr.substr(0, array[i]);
  60. cnt = 0;
  61. }//vypiš zásobník
  62. if(curr > 0) {
  63. cout << expr.substr(0, curr);
  64. }//vypiš current
  65. cout << endl;
  66. //printuj!
  67. }
  68. }
  69. return 0;
  70. }
  71.  

Diff to submission s1204

bugs.cpp

--- c4.s1204.cteam011.bugs.cpp.0.bugs.cpp
+++ c4.s1383.cteam011.bugs.cpp.0.bugs.cpp
@@ -15,4 +15,5 @@
         int exprL = ( int ) expr . length();
         int array[ 2000001 ];
+        if ( ! lines ) cout << endl;
         while ( lines-- )
         {
@@ -62,5 +63,5 @@
                         cout << expr.substr(0, curr);
                 }//vypiš current
-                if ( ch == '\n' ) cout << endl;
+                cout << endl;
                 //printuj!
                 }