Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <string>
- #include <iostream>
- #include <vector>
- #include <cstring>
- using namespace std;
- int main()
- {
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- int n;
- scanf("%d\n",&n);
- string a[15];
- int len[15];
- int ruleKind['z'-'a'+5];
- memset(ruleKind,-1,sizeof(ruleKind));
- for(int i=0;i<n;i++)
- {
- getline(cin,a[i]);
- len[i]=a[i].length();
- for(int j=0;j<len[i];j++)
- {
- ruleKind[a[i][j]-'a']=i;
- }
- }
- string s;
- getline(cin,s);
- if(n==0)
- {
- cout<<s;
- return 0;
- }
- int i,j,k;
- bool c,check;
- while(true)
- {
- c=false;
- i=0;
- while(i<s.length())
- {
- j=ruleKind[s[i]-'a'];
- if(j==-1){i++;continue;}
- if(len[j]+i<=s.length())
- {
- check=true;
- for(k=i;k-i<len[j];k++)
- {
- if(s[k]!=a[j][k-i])
- {
- check=false;
- break;
- }
- }
- if(check)
- {
- s.erase(i,len[j]);
- c=true;
- }
- }
- i++;
- }
- if(!c||s.length()==0)break;
- }
- if(s.length()==0)printf("\n");else cout<<s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement