Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int t,c,d,n,i,l,j,k,q=0,w=0,p,c1,c2;
- cin>>t;
- for(i=0;i<t;i++)
- {
- cin>>c;
- char comb[c][3];
- for(l=0;l<c;l++)
- {
- cin>>comb[l][0];
- cin>>comb[l][1];
- cin>>comb[l][2];
- }
- cin>>d;
- char opp[d][2];
- for(l=0;l<d;l++)
- {
- cin>>opp[l][0];
- cin>>opp[l][1];
- }
- cin>>n;
- char input[n],output[n];
- for(l=0;l<n;l++)
- {
- cin>>input[l];
- //cout<<"\ninputing "<<input[l]<<" -- "<<l<<endl;
- }
- for(c1=0,c2=0,l=0,p=0;l<n;l++)
- {
- //cout<<"\n\nruning\n\n ";
- for(j=0;j<c;j++)
- {
- if(((input[l]==comb[j][0])&&(output[p-1]==comb[j][1]))||((input[l]==comb[j][1])&&(output[p-1]==comb[j][0])))
- {
- //cout<<"1match for combine\nwriting at"<<p<<"--"<<comb[j][2];
- output[p-1]=comb[j][2];l++;
- }
- }
- if(l>=n) break;
- if(input[l]==opp[0][0]) {c1=1;} //add loops for long inputs
- if(input[l]==opp[0][1]) {c2=1;}
- if((c1==1)&&(c2==1))
- {
- // cout<<"match for delete\n";
- for(w=0;w<p;w++) output[w]='\0';c1=0;c2=0;
- p=0;l++;
- }
- if(l>=n) break;
- //cout<<"writing output at "<<p<<"--"<<input[l]<<endl;
- output[p]=input[l];p++;
- }
- /* for(l=0;l<c;l++)
- {
- cout<<endl<<comb[l][0];
- cout<<comb[l][1];
- cout<<comb[l][2]<<" ";
- }
- for(l=0;l<d;l++)
- {
- cout<<endl<<opp[d][0];
- cout<<opp[d][1]<<" ";
- }
- for(l=0;l<n;l++)
- cout<<endl<<input[l]<<"\n";
- */
- cout<<"Case #"<<i+1<<": [";
- for(l=0;l<p-1;l++)
- cout<<output[l]<<", ";
- cout<<output[p-1];
- cout<<"]"<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement