Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. //#include<algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int n,t,i,j,cnt=0;
  8. string a,b;
  9. cin>>n;
  10.  
  11. for(i=0;i<n;i++){
  12. cin>>t;
  13. cin>>a;
  14. cin>>b;
  15. string ans(a);
  16.  
  17. for(j=t-1;j>=0;j--){
  18. if(a[j]=='1'&&b[j]=='1'){
  19. //cout<<cnt<<endl;
  20. if(cnt==1){
  21. ans[j]='1';
  22. }
  23. else {
  24. ans[j]='0';
  25. }
  26. cnt=1;
  27.  
  28. }
  29. else if(a[j]=='0'&&b[j]=='0'){
  30. //cout<<cnt<<endl;
  31. if(cnt==1){
  32. ans[j]='1';
  33.  
  34. }
  35. else{
  36. ans[j]='0';
  37. }
  38. cnt=0;
  39. }
  40. else if((a[j]=='0'&&b[j]=='1')||(a[j]=='1'&&b[j]=='0')){
  41. //cout<<cnt<<endl;
  42. if(cnt==1){
  43. ans[j]='0';
  44. cnt=1;
  45. }
  46. else{
  47. ans[j]='1';
  48. cnt=0;
  49. }
  50.  
  51. }
  52. }
  53. cout<<ans<<endl;
  54.  
  55.  
  56.  
  57.  
  58.  
  59. }
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement