Go to diff to previous submission
#include <cstdio> #include <cstdlib> #include <iostream> #include <cstring> using namespace std; int main() { int n, len; string s; char line[2000000]; char * o, * tmp; while (cin >> n >> s) { getchar(); for (int i=1; i<=n; i++) { len=0; do { line[len++] = getchar(); } while (line[len-1] !='\n'); line[len-1] = 0; tmp = line; while ((o = strstr(tmp, s.c_str()))) { while (tmp < o) { printf("%c", tmp[0]); tmp++; } tmp += s.length(); }; while (tmp < line+len) { printf("%c", tmp[0]); tmp++; } printf("\n"); } } return 0; }
--- c4.s1249.cteam045.bugs.cpp.0.bugs.cpp +++ c4.s1372.cteam045.bugs.cpp.0.bugs.cpp @@ -10,8 +10,8 @@ int main() { - int n, len, ii; + int n, len; string s; char line[2000000]; - char * o; + char * o, * tmp; while (cin >> n >> s) { @@ -19,20 +19,26 @@ for (int i=1; i<=n; i++) { - ii=0; + len=0; do { - line[ii++] = getchar(); - } while (line[ii-1] !='\n'); - line[ii-1] = 0; - len = ii; - while ((o = strstr(line, s.c_str()))) { - while (o < line+len-1) + line[len++] = getchar(); + } while (line[len-1] !='\n'); + line[len-1] = 0; + tmp = line; + + while ((o = strstr(tmp, s.c_str()))) { + + while (tmp < o) { - o++; - o[-1] = o[s.length()-1]; + printf("%c", tmp[0]); + tmp++; } - o[0] = 0; - len -= s.length(); + tmp += s.length(); }; - cout << line << endl; + while (tmp < line+len) + { + printf("%c", tmp[0]); + tmp++; + } + printf("\n"); } }