Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,c,d,n,i,l,j,k,q=0,w=0,p,c1,c2;
  6. cin>>t;
  7. for(i=0;i<t;i++)
  8. {
  9.  
  10. cin>>c;
  11. char comb[c][3];
  12. for(l=0;l<c;l++)
  13. {
  14. cin>>comb[l][0];
  15. cin>>comb[l][1];
  16. cin>>comb[l][2];
  17. }
  18. cin>>d;
  19. char opp[d][2];
  20. for(l=0;l<d;l++)
  21. {
  22. cin>>opp[l][0];
  23. cin>>opp[l][1];
  24. }
  25.  
  26. cin>>n;
  27. char input[n],output[n];
  28. for(l=0;l<n;l++)
  29. {
  30. cin>>input[l];
  31. //cout<<"\ninputing "<<input[l]<<" -- "<<l<<endl;
  32. }
  33. for(c1=0,c2=0,l=0,p=0;l<n;l++)
  34. {
  35. //cout<<"\n\nruning\n\n ";
  36. for(j=0;j<c;j++)
  37. {
  38. if(((input[l]==comb[j][0])&&(output[p-1]==comb[j][1]))||((input[l]==comb[j][1])&&(output[p-1]==comb[j][0])))
  39. {
  40. //cout<<"1match for combine\nwriting at"<<p<<"--"<<comb[j][2];
  41. output[p-1]=comb[j][2];l++;
  42. }
  43. }
  44. if(l>=n) break;
  45. if(input[l]==opp[0][0]) {c1=1;} //add loops for long inputs
  46. if(input[l]==opp[0][1]) {c2=1;}
  47. if((c1==1)&&(c2==1))
  48. {
  49. // cout<<"match for delete\n";
  50. for(w=0;w<p;w++) output[w]='\0';c1=0;c2=0;
  51. p=0;l++;
  52. }
  53.  
  54. if(l>=n) break;
  55. //cout<<"writing output at "<<p<<"--"<<input[l]<<endl;
  56. output[p]=input[l];p++;
  57. }
  58.  
  59. /* for(l=0;l<c;l++)
  60. {
  61. cout<<endl<<comb[l][0];
  62. cout<<comb[l][1];
  63. cout<<comb[l][2]<<" ";
  64. }
  65. for(l=0;l<d;l++)
  66. {
  67. cout<<endl<<opp[d][0];
  68. cout<<opp[d][1]<<" ";
  69. }
  70. for(l=0;l<n;l++)
  71. cout<<endl<<input[l]<<"\n";
  72. */
  73.  
  74. cout<<"Case #"<<i+1<<": [";
  75. for(l=0;l<p-1;l++)
  76. cout<<output[l]<<", ";
  77. cout<<output[p-1];
  78. cout<<"]"<<endl;
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement