➤ Problem Link : 1328C. Ternary XOR
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
string s;
cin>>n;
cin>>s;
string a=s;
string b=s;
bool flag=0;
for(int i=0;i<s.length();i++)
{
if(s[i]=='1')
{
if(!flag)
{
b[i]='0';
flag=1;
}
else
{
a[i]='0';
}
}
if(s[i]=='2')
{
if(!flag)
{
a[i]='1';
b[i]='1';
}
else
{
a[i]='0';
b[i]='2';
}
}
}
cout<<a<<"\n"<<b<<"\n";
}
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
