Go to diff to previous submission
#include<iostream> #include<vector> #include<algorithm> #include<map> #include<set> #include<list> #include<stack> #include<queue> #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> using namespace std; #define FOR(i,a,b) for(int i=a;i<=b;i++) #define PB push_back #define PII pair<int,int> #define PLL pair<ll,ll> #define MP make_pair #define fi first #define se second #define SIZE(s) (int) (s).size() #define INF 987654321 #define ll long long //---------------------- #define MAX 2000047 #define MAX2 1047 char p[MAX2]; char text[MAX]; int N,M; bool ok() { //cout << "idem ok" << N << " " << M << endl; //N je velkost daneho if (N < M-1) return false; if (M > 1 && text[N-(M-1)] != p[0]) return false; if (M>1) { int random_id = rand() % (M-1); //cout << M << " " << random_id << " " << N << " " << (N-(M-2-random_id)) << endl; if (text[N-(M-1-random_id)] != p[random_id]) return false; } int j = M-2; int i = N-1; while(j >= 0 && text[i] == p[j]) { j--; i--; } //cout << j << endl; if (j == -1) return true; return false; } int main() { int q; char c; while(scanf("%d %s",&q,p) == 2) { M = (int) strlen(p); getchar(); while(q--) { N = 0; while((c=getchar()) != '\n') { //cout << "prislo " << c << endl; //FOR(i,0,N-1)putchar(text[i]); putchar('\n'); //cout << N << endl; if (p[M-1] == c && ok()) N -= M-1; else text[N++] = c; //FOR(i,0,N-1)putchar(text[i]); putchar('\n'); //cout << endl; } text[N] = '\0'; FOR(i,0,N-1)putchar(text[i]); putchar('\n'); //printf("%s\n",text); } } return 0; }
--- c4.s1169.cteam075.bugs.cpp.0.bugs.cpp +++ c4.s1212.cteam075.bugs.cpp.0.bugs.cpp @@ -45,4 +45,13 @@ if (N < M-1) return false; + if (M > 1 && text[N-(M-1)] != p[0]) return false; + + if (M>1) + { + int random_id = rand() % (M-1); + //cout << M << " " << random_id << " " << N << " " << (N-(M-2-random_id)) << endl; + if (text[N-(M-1-random_id)] != p[random_id]) return false; + } + int j = M-2; int i = N-1;