Source code for submission s767

bugs.cpp

  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. /*
  7. typedef struct {
  8. const char *needle;
  9. size_t npos;
  10. size_t len;
  11. size_t *prefix_table;
  12. } kmp_ctx;
  13.  
  14. void kmp_init(kmp_ctx *ctx, const char *needle) {
  15. size
  16. }
  17. */
  18.  
  19. int main(void) {
  20. int T;
  21. char B[1024];
  22. char line[2000004];
  23.  
  24. char line2[2000004];
  25.  
  26. int Blen;
  27.  
  28. while (scanf(" %d %s", &T, B) != EOF) {
  29. Blen = strlen(B);
  30.  
  31. for (int i = 0; i < T; i++) {
  32. fgets(line, 2000004, stdin);
  33. int line_len = strlen(line);
  34.  
  35. char *s = line;
  36. char *out = line2;
  37. bool changed;
  38. do {
  39. char *f;
  40. changed = false;
  41. while ((f = strstr(s, B)) != NULL) {
  42. changed = true;
  43. while (s != f) {
  44. *(out++) = *(s++);
  45. }
  46. s += Blen;
  47. }
  48. strcpy(out, s);
  49.  
  50. memcpy(line, line2, line_len);
  51. s = line;
  52. out = line2;
  53. } while (changed);
  54.  
  55. printf("%s", line);
  56. }
  57. }
  58.  
  59. return 0;
  60. }
  61.