Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- char jog(char x,char y)
- {
- if(x=='0')
- return y;
- else if(y=='0')
- return x;
- else if(x=='V')
- return y;
- else if(y=='V')
- return x;
- else if(x=='U'&&y=='U')
- return 'C';
- else if(x=='C'&& y=='C')
- return 'V';
- else if(x=='U'&&y=='C'||x=='C'&& y=='U')
- return 'D';
- else if(x=='C'&&y=='D'||x=='D'&& y=='C')
- return 'U';
- else if(x=='U'&&y=='D'||x=='D'&& y=='U')
- return 'V';
- }
- char carry(char x,char y)
- {
- if(x=='U'&&y=='D'||x=='D'&&y=='U')
- return 'U';
- else if(x=='C'&& y=='C')
- return 'U';
- else if(x=='D'&& y=='D')
- return 'U';
- else if(x=='C'&&y=='D'||x=='D'&&y=='C')
- return 'U';
- else
- return '0';
- }
- int main()
- {
- freopen("in.txt","r",stdin);
- freopen("out.txt","w",stdout);
- int t,i,j,k,l1,l2;
- string s1,s2,s3,ans;
- cin>>t;
- cout<<"COWCULATIONS OUTPUT"<<endl;
- while(t--)
- {
- cin>>s1>>s2;
- char c,num1,num2,num3,pre='0',carry1,carry2;
- // string ans="";
- for(j=1;j<=3;j++)
- {
- cin>>c;
- if(c=='A')
- {
- l1=s1.length()-1,l2=s2.length()-1;
- string res="";
- for(i=l1;i>=0;i--)
- {
- num1=jog(s1[i],s2[l2]);
- carry1=carry(s1[i],s2[l2]);
- num2=jog(num1,pre);
- carry2=carry(num1,pre);
- res+=num2;
- // cout<<"vitore ans1 "<<ans<<endl;
- pre=max(carry1,carry2);
- l2--;
- }
- while(l2>=0)
- {
- num1=jog(s2[l2],pre);
- carry1=carry(s2[l2],pre);
- res+=num1;
- // cout<<"vitore ans2 "<<ans<<endl;
- pre=carry1;
- l2--;
- }
- if(pre!='0')
- res+=pre;
- reverse(res.begin(),res.end());
- // cout<<"ans is "<<ans<<endl;
- s2=res;
- }
- else if(c=='L')
- {
- s2=s2+'V';
- }
- else if(c=='R')
- {
- s2='V'+s2;
- int len=s2.length()-1;
- s2.erase(s2.begin()+len);
- }
- else
- continue;
- }
- while(s2.size()<8)
- {
- s2='V'+s2;
- }
- // cout<<"final s2 "<<s2<<endl;
- cin>>s3;
- if(s3==s2)
- cout<<"YES"<<endl;
- else
- cout<<"NO"<<endl;
- }
- cout<<"END OF OUTPUT"<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement