Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 30 January 2023 [21:31]
- */
- #include<bits/stdc++.h>
- using namespace std;
- char a[1000010],b[1000010];
- int prep[1000010];
- char ans[1000010];
- int jump[1000010];
- int main(){
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- int q;
- cin >> q;
- while(q--){
- cin >> a+1 >> b+1;
- int lena = strlen(a+1),lenb = strlen(b+1);
- int j = 0;
- for(int i=2;i<=lenb;i++){
- while(j>0 && b[j+1]!=b[i]) j = prep[j];
- if(b[j+1]==b[i]) j++;
- prep[i] = j;
- }
- j=0;
- int idx=0;
- for(int i=1;i<=lena;i++){
- while(j>0 && b[j+1]!=a[i]) j = prep[j];
- if(b[j+1]==a[i]) j++;
- ans[++idx] = a[i];
- jump[idx] = j;
- if(j == lenb){
- idx-=lenb;
- j = jump[idx];
- }
- }
- ans[idx+1] = '\0';
- if(idx == 0) cout << "No COI Secret Code\n";
- else cout << ans+1 << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement