Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <cstdio>
  2. #include <string>
  3. #include <iostream>
  4. #include <vector>
  5. #include <cstring>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     freopen("input.txt","r",stdin);
  12.     freopen("output.txt","w",stdout);
  13.     int n;
  14.     scanf("%d\n",&n);
  15.     string a[15];
  16.     int len[15];
  17.     int ruleKind['z'-'a'+5];
  18.     memset(ruleKind,-1,sizeof(ruleKind));
  19.     for(int i=0;i<n;i++)
  20.     {
  21.        getline(cin,a[i]);
  22.        len[i]=a[i].length();  
  23.        for(int j=0;j<len[i];j++)
  24.        {
  25.           ruleKind[a[i][j]-'a']=i;    
  26.        }
  27.     }
  28.     string s;
  29.     getline(cin,s);
  30.     if(n==0)
  31.     {
  32.       cout<<s;
  33.       return 0;      
  34.     }
  35.     int i,j,k;
  36.     bool c,check;
  37.     while(true)
  38.     {
  39.         c=false;
  40.         i=0;
  41.         while(i<s.length())
  42.         {
  43.             j=ruleKind[s[i]-'a'];
  44.            if(j==-1){i++;continue;}
  45.                if(len[j]+i<=s.length())
  46.                {
  47.                  check=true;            
  48.                  for(k=i;k-i<len[j];k++)
  49.                  {
  50.                     if(s[k]!=a[j][k-i])
  51.                     {
  52.                        check=false;
  53.                        break;                
  54.                     }
  55.                  }
  56.                  if(check)
  57.                  {
  58.                    s.erase(i,len[j]);  
  59.                    c=true;
  60.                  }                                        
  61.                }    
  62.            
  63.            i++;    
  64.         }
  65.         if(!c||s.length()==0)break;
  66.     }
  67.     if(s.length()==0)printf("\n");else cout<<s;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement