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