Source code for submission s733

bugs.cpp

  1. #include <cstdlib>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <cctype>
  5.  
  6. size_t mygets (char *out)
  7. {
  8. int c;
  9. char *pout = out;
  10. while ((c = getchar ()) != '\n')
  11. *pout++ = c;
  12. *pout = '\0';
  13. return pout - out;
  14. }
  15.  
  16. int main ()
  17. {
  18. int line_no;
  19. while (scanf ("%d", &line_no) == 1)
  20. {
  21. int c;
  22. getchar ();
  23.  
  24. static char marker[1001] = {0};
  25. char *pmarker = marker;
  26. while ((c = getchar ()) != '\n')
  27. if (isalpha (c))
  28. *pmarker++ = c;
  29. *pmarker = '\0';
  30. size_t marker_len = pmarker - marker;
  31.  
  32. while (line_no--)
  33. {
  34. static char line[2000001] = {0};
  35. char *pline = line;
  36. size_t line_len = mygets (line) + 1;
  37.  
  38. char *pbug;
  39. while ((pbug = strstr (pline, marker)))
  40. {
  41. line_len -= marker_len;
  42. memmove (pbug, pbug + marker_len, line_len - (pbug - line));
  43.  
  44. pline = pbug - marker_len;
  45. if (pline < line)
  46. pline = line;
  47. }
  48. puts (line);
  49. }
  50. }
  51. return 0;
  52. }
  53.  
  54.