三元数异或

三元数异或

AcWing 3764
https://www.acwing.com/problem/content/3767/
贪心

思路

代码

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        
        string x;
        cin >> x;
        
        string a, b;
        bool flag = false;
        for (auto c:x)
        {
            if (c == '0') a += '0', b += '0';
            else if (c == '1')
            {
                if (flag) a += '0', b += '1';
                else a += '1', b +='0', flag = true;
            }
            else
            {
                if (flag) a += '0', b += '2';
                else a += '1',b +='1';
            }
        }
        
        cout << a << endl << b << endl;
    }
    return 0;
}
posted @ 2021-07-17 18:15  Treasure_lee  阅读(84)  评论(0编辑  收藏  举报