Submission #499097

#TimeUsernameProblemLanguageResultExecution timeMemory
499097LouayFarahIgra (COCI17_igra)C++14
100 / 100
1 ms332 KiB
#include "bits/stdc++.h"

using namespace std;

#define endl "\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const long long MOD = 1e9+7;
const long long INF = 1e18;

int nx[4] = {0, 0, -1, 1};
int ny[4] = {1, -1, 0, 0};


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    ll n;
    cin >> n;

    string x, y;
    cin >> x >> y;

    ll a = 0, b = 0, c = 0;
    ll A = 0, B = 0, C = 0;

    for(int i = 0; i<n; i++)
    {
        if(x[i]=='a')
            a++;
        if(x[i]=='b')
            b++;
        if(x[i]=='c')
            c++;
    }

    for(int i = 0; i<n; i++)
    {
        if(y[i]=='a')
            A++;
        if(y[i]=='b')
            B++;
        if(y[i]=='c')
            C++;
    }

    string res = "";

    for(int i = 0; i<n; i++)
    {
        char ch = y[i];

        if(ch=='a')
        {
            if(a+b<=C||b==0)
            {
                res.pb('c');
                c--;
            }
            else
            {
                res.pb('b');
                b--;
            }
            A--;
        }
        if(ch=='b')
        {
            if(a+b<=C||a==0)
            {
                res.pb('c');
                c--;
            }
            else
            {
                res.pb('a');
                a--;
            }
            B--;
        }
        if(ch=='c')
        {
            if(a+c<=B||a==0)
            {
                res.pb('b');
                b--;
            }
            else
            {
                res.pb('a');
                a--;
            }
            C--;
        }
    }

    cout << res << endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...