Guest User

Untitled

a guest
Jun 7th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.93 KB | None | 0 0
  1.     #include<bits/stdc++.h>
  2.     using namespace std;
  3.     #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  4.     #define pb push_back
  5.     #define ll long long
  6.     ll mod=1e9+7;
  7.  
  8.  
  9.     void test_case()
  10.     {
  11.             string a,b;
  12.             cin>>a>>b;
  13.             if(a.size()!=b.size()) {
  14.                 cout<<"NO";
  15.                 return;
  16.             }
  17.             bool flag=1;
  18.             int n=a.size();
  19.             for(int i=0;i<n-1;i++) {
  20.  
  21.                 if(a.substr(i,2)!=b.substr(i,2)) {
  22.                     // 11 --> 10 01
  23.                     // 10 --> 11
  24.                     // 01 --> 11
  25.                     // 00 --> 00
  26.                     if(a.substr(i,2)=="11")
  27.                     {
  28.                         if(b.substr(i,2)=="01" || b.substr(i,2)=="10")
  29.                         {
  30.                             a[i]=b[i];
  31.                             a[i+1]=b[i+1];
  32.                         }
  33.                         else
  34.                         {
  35.                             flag=0;
  36.                             break;
  37.                         }
  38.                     }
  39.                     else if(a.substr(i,2)=="10" || a.substr(i,2)=="01")
  40.                     {
  41.                         if(b.substr(i,2)=="11")
  42.                         {
  43.                             a[i]=b[i];
  44.                             a[i+1]=b[i+1];
  45.                         }
  46.                         else{
  47.                             flag=0;
  48.                             break;
  49.                         }
  50.                     }
  51.                     else {
  52.                         flag=0;
  53.                         break;
  54.                     }
  55.                 }
  56.             }
  57.             if(flag && a==b)
  58.                 cout<<"YES";
  59.             else
  60.                 cout<<"NO";
  61.     }
  62.  
  63.  
  64.     int main()
  65.     {
  66.         fastio
  67. //        int t;
  68. //        cin>>t;
  69. //        while(t--)
  70.         test_case();
  71.     }
Add Comment
Please, Sign In to add comment