193362025-12-04 21:16:35szabelrTáblajátékcpp17Forditási hiba
// 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();
                    binary[y] = 0;
                    egyes = y;
                    break;
                }
                

            }
            
            else
            {
                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
Forditási hiba
open /var/local/lib/isolate/416/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:44:13: error: expected '}' before 'else'
   44 |             else
      |             ^~~~
main.cpp:28:21: note: to match this '{'
   28 |         if (x == 3) {
      |                     ^
main.cpp:46:30: error: 'egyes' was not declared in this scope
   46 |                 for (int y = egyes + 1; y <= binary.size() - 1; y++)
      |                              ^~~~~
main.cpp: At global scope:
main.cpp:75:5: error: 'cout' does not name a type
   75 |     cout << height << endl;
      |     ^~~~
main.cpp:76:5: error: expected unqualified-id before 'if'
   76 |     if (binary.empty())
      |     ^~
main.cpp:78:5: error: expected unqualified-id before 'for'
   78 |     for (int i = 0; i < binary.size(); i++)
      |     ^~~
main.cpp:78:21: error: 'i' does not name a type
   78 |     for (int i = 0; i < binary.size(); i++)
      |                     ^
main.cpp:78:40: error: 'i' does not name a type
   78 |     for (int i = 0; i < binary.size(); i++)
      |                                        ^
main.cpp:82:1: error: expected declaration before '}' token
   82 | }
      | ^