Go to diff to previous submission
#include <stdio.h> #include <string.h> int q, ind, pozicia; char bug[1200]; char line[2000009]; char readed[2000009]; char tmpLine[1500]; int c; bool jeVslove() { int len = strlen(bug); if(ind < len) return false; for(int i = len-1; i >= 0; i--) { if(bug[i] != line[ind-len+i]) { return false; } } return true; } int main() { while(fgets(tmpLine, 1300, stdin) != NULL) { sscanf(tmpLine, "%d %s", &q, bug); //printf("%d", q); for(int i = 0; i<q; i++) { pozicia = 0; if(fgets(readed, 2000005, stdin) == NULL) break; ind = 0; while(true) { c = readed[pozicia]; pozicia++; //printf("%c", c); line[ind] = c; ind++; if(c == '\n' || c == EOF) { line[ind] = 0; //printf("%s", line); fputs(line, stdout); break; } if(jeVslove()) { ind -= strlen(bug); } } } } return 0; }
--- c4.s1147.cteam122.bugs.cpp.0.bug.cpp +++ c4.s1235.cteam122.bugs.cpp.0.bug.cpp @@ -2,8 +2,9 @@ #include <string.h> -int q, ind; +int q, ind, pozicia; char bug[1200]; char line[2000009]; -char tmpLine[10000]; +char readed[2000009]; +char tmpLine[1500]; int c; @@ -28,5 +29,5 @@ int main() { - while(fgets(tmpLine, 9999, stdin) != NULL) + while(fgets(tmpLine, 1300, stdin) != NULL) { sscanf(tmpLine, "%d %s", &q, bug); @@ -34,15 +35,18 @@ for(int i = 0; i<q; i++) { + pozicia = 0; + + if(fgets(readed, 2000005, stdin) == NULL) + break; + ind = 0; while(true) { - c = getchar(); + c = readed[pozicia]; + pozicia++; //printf("%c", c); - if(c != EOF) - { - line[ind] = c; - ind++; - } + line[ind] = c; + ind++; if(c == '\n' || c == EOF)