28912023-02-02 09:31:05tamasmarkTáblajátékcpp17Elfogadva 50/503ms3920 KiB
// tablajatek.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <deque>

using namespace std;

int n, sor, hely, i, a,j;
deque<int>x;

int main()
{
    cin >> n;
    x.push_back(0);
    for (i = 1; i<=n; ++i)
    {
        cin >> a;
        if (a == 0)
        {
            sor++;
            //hely = hely * 2;
            x.push_back(0);
        }
        else if (a == 1)
        {
            sor++;
            //hely = (hely * 2) + 1;
            x.push_back(1);

        }
        else if (a == 2)
        {
            sor--;
            /*if (hely % 2 == 0)
            {
                hely = hely / 2;
            }
            else if (hely % 2 != 0)
            {
                hely = hely - 1;
                hely = hely / 2;
            }*/
            x.pop_back();
        }
        else if (a == 3)
        {
            //hely--;
            if (x.back() == 1) x.back()=0;
            else
            {
                j = x.size() - 1;
                while (x[j] == 0)
                {
                    x[j] = 1;
                    j--;
                }
            x[j] = 0;
            }
            
        }
        else if (a == 4)
        {
            //hely++;
            if (x.back() == 0) x.back()=1;
            else
            {
                j = x.size() - 1;
                while (x[j] == 1)
                {
                    x[j] = 0;
                    j--;
                }
                x[j] = 1;
            }
        }
    }
    while (x.size() > 1 && x.front() == 0) x.pop_front();
    /*while (hely / 2)
    {
        if (hely % 2==0)
        {
            x.push_front(0);
        }
        else
        {
            x.push_front(1);
        }
        hely = hely / 2;
    }
    if (hely % 2 == 0) x.push_front(0);
    else x.push_front(1);*/
    cout << sor << "\n";
    for (i = 0; i < x.size(); ++i)
    {
        cout << x[i];
    }
    return 0;
}
/*
6 
0 1 4 2 1 0
6 
0 0 0 0 0 0
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms1816 KiB
2Elfogadva0/03ms2000 KiB
3Elfogadva3/33ms2216 KiB
4Elfogadva3/33ms2300 KiB
5Elfogadva3/32ms2428 KiB
6Elfogadva3/33ms2816 KiB
7Elfogadva3/33ms2860 KiB
8Elfogadva3/32ms2940 KiB
9Elfogadva3/32ms3072 KiB
10Elfogadva3/33ms3312 KiB
11Elfogadva3/32ms3312 KiB
12Elfogadva3/32ms3304 KiB
13Elfogadva4/43ms3432 KiB
14Elfogadva4/43ms3664 KiB
15Elfogadva4/43ms3720 KiB
16Elfogadva4/43ms3828 KiB
17Elfogadva4/43ms3920 KiB