Source code for submission s779

Go to diff to previous submission

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) == 2) {
  29. Blen = strlen(B);
  30.  
  31. while (getchar() != '\n');
  32.  
  33. for (int i = 0; i < T; i++) {
  34. fgets(line, 2000004, stdin);
  35. int line_len = strlen(line);
  36.  
  37. char *s = line;
  38. char *out = line2;
  39. bool changed;
  40. do {
  41. char *f;
  42. changed = false;
  43. while ((f = strstr(s, B)) != NULL) {
  44. changed = true;
  45. while (s != f) {
  46. *(out++) = *(s++);
  47. }
  48. s += Blen;
  49. }
  50. strcpy(out, s);
  51.  
  52. memcpy(line, line2, line_len);
  53. s = line;
  54. out = line2;
  55. } while (changed);
  56.  
  57. printf("%s", line);
  58. }
  59. }
  60.  
  61. return 0;
  62. }
  63.  

Diff to submission s767

bugs.cpp

--- c4.s767.cteam091.bugs.cpp.0.bugs.cpp
+++ c4.s779.cteam091.bugs.cpp.0.bugs.cpp
@@ -26,7 +26,9 @@
         int Blen;
 
-        while (scanf(" %d %s", &T, B) != EOF) {
+        while (scanf(" %d %s", &T, B) == 2) {
                 Blen = strlen(B);
                 
+                while (getchar() != '\n');
+                
                 for (int i = 0; i < T; i++) {
                         fgets(line, 2000004, stdin);