Advertisement
Farjana_akter

Untitled

Sep 7th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. char jog(char x,char y)
  6. {
  7. if(x=='0')
  8. return y;
  9. else if(y=='0')
  10. return x;
  11. else if(x=='V')
  12. return y;
  13. else if(y=='V')
  14. return x;
  15. else if(x=='U'&&y=='U')
  16. return 'C';
  17. else if(x=='C'&& y=='C')
  18. return 'V';
  19. else if(x=='U'&&y=='C'||x=='C'&& y=='U')
  20. return 'D';
  21. else if(x=='C'&&y=='D'||x=='D'&& y=='C')
  22. return 'U';
  23. else if(x=='U'&&y=='D'||x=='D'&& y=='U')
  24. return 'V';
  25. }
  26.  
  27. char carry(char x,char y)
  28. {
  29. if(x=='U'&&y=='D'||x=='D'&&y=='U')
  30. return 'U';
  31. else if(x=='C'&& y=='C')
  32. return 'U';
  33. else if(x=='D'&& y=='D')
  34. return 'U';
  35. else if(x=='C'&&y=='D'||x=='D'&&y=='C')
  36. return 'U';
  37. else
  38. return '0';
  39. }
  40.  
  41.  
  42. int main()
  43. {
  44. freopen("in.txt","r",stdin);
  45. freopen("out.txt","w",stdout);
  46. int t,i,j,k,l1,l2;
  47. string s1,s2,s3,ans;
  48. cin>>t;
  49. cout<<"COWCULATIONS OUTPUT"<<endl;
  50. while(t--)
  51. {
  52. cin>>s1>>s2;
  53. char c,num1,num2,num3,pre='0',carry1,carry2;
  54. // string ans="";
  55. for(j=1;j<=3;j++)
  56. {
  57. cin>>c;
  58. if(c=='A')
  59. {
  60. l1=s1.length()-1,l2=s2.length()-1;
  61. string res="";
  62. for(i=l1;i>=0;i--)
  63. {
  64. num1=jog(s1[i],s2[l2]);
  65. carry1=carry(s1[i],s2[l2]);
  66. num2=jog(num1,pre);
  67. carry2=carry(num1,pre);
  68. res+=num2;
  69. // cout<<"vitore ans1 "<<ans<<endl;
  70. pre=max(carry1,carry2);
  71. l2--;
  72. }
  73. while(l2>=0)
  74. {
  75. num1=jog(s2[l2],pre);
  76. carry1=carry(s2[l2],pre);
  77. res+=num1;
  78. // cout<<"vitore ans2 "<<ans<<endl;
  79. pre=carry1;
  80. l2--;
  81. }
  82. if(pre!='0')
  83. res+=pre;
  84. reverse(res.begin(),res.end());
  85. // cout<<"ans is "<<ans<<endl;
  86. s2=res;
  87.  
  88. }
  89. else if(c=='L')
  90. {
  91. s2=s2+'V';
  92. }
  93. else if(c=='R')
  94. {
  95. s2='V'+s2;
  96. int len=s2.length()-1;
  97. s2.erase(s2.begin()+len);
  98.  
  99.  
  100. }
  101. else
  102. continue;
  103. }
  104. while(s2.size()<8)
  105. {
  106. s2='V'+s2;
  107. }
  108. // cout<<"final s2 "<<s2<<endl;
  109. cin>>s3;
  110. if(s3==s2)
  111. cout<<"YES"<<endl;
  112. else
  113. cout<<"NO"<<endl;
  114. }
  115. cout<<"END OF OUTPUT"<<endl;
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement