Source code for submission s1295

Go to diff to previous submission

bugs.c

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char bug[2000];
  6. char line[3000000];
  7. char lineo[3000000];
  8. int lineop;
  9. int main(int argc, char **argv)
  10. {
  11. int lines, linel, i, bugl, f, nostart;
  12. while (1) {
  13. scanf("%d ", &lines);
  14. if (feof(stdin))
  15. break;
  16. gets(bug);
  17. bugl = strlen(bug);
  18. while (lines--) {
  19. lineop = 0;
  20. gets(line);
  21. linel=strlen(line);
  22. for (i=0; i<linel;i++) {
  23. lineo[lineop++] = line[i];
  24. lineo[lineop] = 0;
  25. if (lineop >= bugl && strncmp(bug, lineo+lineop-bugl, bugl) == 0) {
  26. //printf("Found bug %d %d\n", i, lineop);
  27. lineop -= bugl;
  28. }
  29. }
  30. lineo[lineop] = 0;
  31. printf("%s\n", lineo);
  32. }
  33.  
  34. }
  35. return 0;
  36. }
  37.  

Diff to submission s1256

bugs.c

--- c4.s1256.cteam129.bugs.c.0.bugs.c
+++ c4.s1295.cteam129.bugs.c.0.bugs.c
@@ -7,22 +7,4 @@
 char lineo[3000000];
 int lineop;
-int stack[3000000];
-int stackp;
-
-void push(int val)
-{
-        stack[stackp++] = val;
-}
-
-int pop()
-{
-        return stack[--stackp];
-}
-
-int top()
-{
-        return stack[stackp-1];
-}
-
 int main(int argc, char **argv)
 {
@@ -35,42 +17,13 @@
                 bugl = strlen(bug);
                 while (lines--) {
-                        stackp=0;
                         lineop = 0;
                         gets(line);
                         linel=strlen(line);
-                        nostart = 0;
                         for (i=0; i<linel;i++) {
                                 lineo[lineop++] = line[i];
                                 lineo[lineop] = 0;
-                                sem:
-                                f = 0;
-                                if (nostart==0 && bug[0] == line[i]) {
-                                        //printf("Start %d %s %s\n", i, lineo, line+i);
-                                        push(1);
-                                        f = 1;
-                                }
-                                else if (stackp && bug[top()] == line[i]) {
-                                        //printf("Cont %d %d %s %s\n", i, top(), lineo, line+i);
-                                        push(pop()+1);
-                                        if (top() == bugl) {
-                                                lineop -= bugl;
-                                                pop();
-                                                lineo[lineop] = 0;
-                                                //printf("OK %s %s\n", lineo, line+i);
-                                        }
-                                        f = 1;
-                                        nostart = 0;
-                                }
-                                else if (!f) {
-                                        if (stackp) {
-                                                //printf("Fail %d %d %s %s\n", i, top(), lineo, line+i);
-                                                int rem = pop();
-                                                lineop -= 1;
-                                                i -= 1;
-                                                nostart = 1;
-                                                goto sem;
-                                                continue;
-                                        }
-                                        //else printf("FailE %d %d %s %s\n", i, top(), lineo, line+i);
+                                if (lineop >= bugl && strncmp(bug, lineo+lineop-bugl, bugl) == 0) {
+                                        //printf("Found bug %d %d\n", i, lineop);
+                                        lineop -= bugl;
                                 }
                         }
@@ -78,4 +31,5 @@
                         printf("%s\n", lineo);
                 }
+                
         }
         return 0;