Source code for submission s1093

bug.cpp

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int q, ind;
  5. char bug[1200];
  6. char line[2000009];
  7. char tmpLine[10000];
  8. char c;
  9.  
  10. bool jeVslove()
  11. {
  12. int len = strlen(bug);
  13.  
  14. if(ind < len)
  15. return false;
  16.  
  17. for(int i = len-1; i >= 0; i--)
  18. {
  19. if(bug[i] != line[ind-len+i])
  20. {
  21. return false;
  22. }
  23. }
  24.  
  25. return true;
  26. }
  27.  
  28. int main()
  29. {
  30. while(fgets(tmpLine, 9999, stdin) != NULL)
  31. {
  32. sscanf(tmpLine, "%d %s", &q, bug);
  33. //printf("%d", q);
  34. for(int i = 0; i<q; i++)
  35. {
  36. ind = 0;
  37. while(true)
  38. {
  39. c = getchar();
  40. //printf("%c", c);
  41. if(c == '\n')
  42. {
  43. line[ind] = 0;
  44. printf("%s\n", line);
  45. break;
  46. }
  47.  
  48. line[ind] = c;
  49. ind++;
  50.  
  51. if(jeVslove())
  52. {
  53. ind -= strlen(bug);
  54. }
  55.  
  56. }
  57. }
  58. }
  59.  
  60.  
  61. return 0;
  62. }