Codeforces Round #629 (Div. 3) 1328C - Ternary XOR Solution





///******Bismillahir-Rahmanir-Rahim******///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t,n,i;
    cin>>t;
    while(t--)
    {
        string s,a,b;
        cin>>n>>s;
        a="",b="";
        for(i=0; i<n; i++)
        {
            if(s[i]=='0')
                a+="0",b+="0";
            else if(s[i]=='1')
            {
                if(a>=b)
                    a+="0",b+="1";
                else
                    a+="1",b+="0";
            }
            else
            {
                if(a>b)
                    a+="0",b+="2";
                else if(a<b)
                    a+="2",b+="0";
                else
                    a+="1",b+="1";
            }
        }
        cout<<a<<"\n"<<b<<"\n";
    }
    return 0;
}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.