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