Source code for submission s1033

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.  
  15. cin . get();
  16. int exprL = ( int ) expr . length();
  17. int array[ 2000001 ];
  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(ch == expr[curr] && curr > 0) curr++;
  29. else if(ch == expr[0]) {
  30. if(curr > 0) array[cnt++] = curr;
  31. curr = 1;
  32. }
  33. else {
  34. if(cnt > 0) {
  35. for(int i = 0; i < cnt; i++) cout << expr.substr(0, array[i]);
  36. cnt = 0;
  37. }//vypiš zásobník
  38. if(curr > 0) {
  39. cout << expr.substr(0, curr);
  40. }//vypiš current
  41. cout << ch;
  42. cnt = 0;
  43. curr = 0;
  44. }
  45.  
  46. if ( curr == exprL ) {
  47. if(cnt > 0) curr = array[--cnt];
  48. else curr = 0;
  49. }//načti předchozí ze zásobníku
  50.  
  51.  
  52. }
  53. if(cnt > 0) {
  54. for(int i = 0; i < cnt; i++) cout << expr.substr(0, array[i]);
  55. cnt = 0;
  56. }//vypiš zásobník
  57. if(curr > 0) {
  58. cout << expr.substr(0, curr);
  59. }//vypiš current
  60. cout << endl;
  61. //printuj!
  62. }
  63. }
  64. return 0;
  65. }
  66.