Codeforces Round #629 (Div. 3) C贪心

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#define inf 0x3f3f3f3f
#define sd(a) scanf("%d",&a)
#define mem0(a) memset(a,0,sizeof(a))
typedef long long ll;
const int mod = 998244353;
const int maxn = 1e5+10;
int a[maxn],b[maxn];
using namespace std;
string c;


int main()
{
    
    
    int t;
    sd(t);
    while(t--)
    {
    
    
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        int n,cur;
        int flag = 0;
        sd(n);
        a[0] = 1,b[0] = 1;
        cin>>c;
        cur = 1;
        for(int i = 1;i < n;i++)
        {
    
    
            if(c[i] == '2')
            {
    
    
                if(flag == 1)
                {
    
    
                    b[cur] += 2;
                }
                else if(flag == 2)
                {
    
    
                    a[cur] += 2;
                }
                else{
    
    
                if(a[cur-1] == 0&&b[cur-1] == 0){
    
    
                a[cur]+=1;b[cur]+=1;
                }
                else if(a[cur-1] == 0){
    
    
                a[cur]+=2;
                flag = 1;
                }
                else if(b[cur-1] == 0){
    
    
                b[cur]+=2;
                flag = 2;
                }
                else{
    
    
                a[cur]+=1;b[cur]+=1;
                }
                }
            }
            else if(c[i] == '1')
            {
    
    
                if(flag == 2)
                {
    
    
                    a[cur]+=1;
                }
                else if(flag == 1)
                {
    
    
                    b[cur]+=1;
                }
                else{
    
    
                    a[cur]+=1;
                    flag = 1;
                }
            }
                cur++;

        }
        for(int i = 0;i < n;i++)cout<<a[i];
        cout<<endl;
        for(int i = 0;i < n;i++)cout<<b[i];
        cout<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42937838/article/details/105278499