-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathternaryxor.cpp
More file actions
65 lines (61 loc) · 1.28 KB
/
ternaryxor.cpp
File metadata and controls
65 lines (61 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std;
// https://codeforces.com/contest/1328/problem/C
#define ll long long
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define MOD 1000000007
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while (t--)
{
int n;
cin>>n;
string x,a,b;
cin>>x;
a=b=x;
a[0]=b[0]='1';
bool chk=false;
for(int i=1;i<n;i++)
{
if(x[i]=='2')
{
if(x[i-1]=='1' or chk)
{
a[i]='2';
b[i]='0';
chk=true;
}
else
{
a[i]=b[i]='1';
chk=false;
}
}
else if(x[i]=='1')
{
if(chk)
{
a[i]='1';
b[i]='0';
}
else
{
a[i]='0';
b[i]='1';
chk=true;
}
}
else
{
a[i]=b[i]='0';
}
}
cout<<a<<endl<<b<<endl;
}
return 0;
}