Source code for submission s1064

bugs.cpp

  1.  
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <string.h>
  6.  
  7. using namespace std;
  8.  
  9. char buf[2][2000002];
  10. char tbuf[1002];
  11.  
  12. bool cutBugs(char *d, const char *s, const char *t) {
  13. bool result = false;
  14. int sp = 0;
  15. int dp = 0;
  16. int tp = 0;
  17. for (sp = 0; s[sp]; sp++) {
  18. if (!t[tp]) {
  19. dp -= tp;
  20. tp = 0;
  21. result = true;
  22. }
  23. if (tp && s[sp] == t[tp])
  24. tp++;
  25. else
  26. tp = s[sp] == t[0];
  27. d[dp++] = s[sp];
  28. }
  29. if (!t[tp]) {
  30. dp -= tp;
  31. tp = 0;
  32. result = true;
  33. }
  34. d[dp] = 0;
  35. return result;
  36. }
  37.  
  38. int main(int argc, char** argv) {
  39.  
  40. int lines;
  41. while (scanf("%d %s", &lines, tbuf) == 2) {
  42.  
  43. getchar();
  44.  
  45. for (int i = 0; i < lines; i++) {
  46.  
  47. cin.getline(buf[0], 2000001);
  48.  
  49. for (bool a = false; cutBugs(buf[!a], buf[a], tbuf); a = !a);
  50.  
  51. cout << buf[0] << endl;
  52.  
  53.  
  54. }
  55. }
  56.  
  57. return 0;
  58. }
  59.  
  60.