193442025-12-04 21:39:52szabelrTáblajátékcpp17Futási hiba 34/502ms508 KiB
// Táblajáték.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int k, x,height=0;
    vector<int> binary;
    cin >> k;
    for (int i = 0; i < k; i++)
    {
        cin >> x;
        if (x == 0) {
            height++;
            if (!binary.empty())
                binary.push_back(0);
        }
        if (x == 1) {
            height++;
            binary.push_back(1);
        }
        if (x == 2) {
            height--;
            binary.pop_back();
        }
        if (x == 3) {
            int egyes = -1;
            for (int y = binary.size() - 1; y >=0; y--)
            {
                if (binary[y] == 1)
                {
                    if (y == 0)
                    {
                        binary.pop_back();
                        egyes = y-1;
                        break;
                    }
                    else    

                    {
                        binary[y] = 0;
                        egyes = y;
                        break;
                    }
                }
                

            }
             for (int y = egyes + 1; y <= binary.size() - 1; y++)
                   binary[y] = 1;
            
        }
        if (x == 4) {
            int nulla = -1;
            for (int y = binary.size() - 1; y >= 0; y--)
            {
                if (binary[y] == 0)
                {
                    binary[y] = 1;
                    nulla = y;
                    break;
                }
            }

            if (nulla == -1) {
                binary.push_back(0);
                for (int y = 1; y < binary.size() - 1; y++)
                {
                    binary[y] = 0;
                }
            }
            else
            {
                for (int y = nulla + 1; y <= binary.size() - 1; y++)
                    binary[y] = 0;
            }
        }
    }
    cout << height << endl;
    if (binary.empty())
        cout << 0;
    for (int i = 0; i < binary.size(); i++)
    {
        cout << binary[i];
    }
}

// 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
base34/50
1Elfogadva0/01ms316 KiB
2Elfogadva0/01ms316 KiB
3Elfogadva3/31ms316 KiB
4Elfogadva3/31ms316 KiB
5Elfogadva3/31ms316 KiB
6Elfogadva3/31ms508 KiB
7Elfogadva3/31ms316 KiB
8Elfogadva3/31ms316 KiB
9Futási hiba0/31ms316 KiB
10Futási hiba0/31ms316 KiB
11Elfogadva3/32ms316 KiB
12Elfogadva3/31ms316 KiB
13Részben helyes1/41ms316 KiB
14Részben helyes1/41ms316 KiB
15Elfogadva4/42ms316 KiB
16Elfogadva4/42ms316 KiB
17Futási hiba0/42ms316 KiB