34072023-02-27 13:21:13CWMTáblajátékcpp17Compilation error
// 0227.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
using ll = long long;
int helpnum1 = INT_MAX / 2;
int level = 0;
string ConvertToBits(int a) {
	ll divisor = INT_MAX;
	divisor++;
	string s = "";
	for (size_t i = 0; i < 32; i++)
	{
		if (a - divisor >= 0) {
			s += '1';
			a -= divisor;
		}
		else s += '0';
		divisor /= 2;
	}
	return s;
}
vector<ll> move(vector<ll> base, char instructionNum) {
	if (instructionNum == 0) {
		level++;
		base[7] *= 2;
		for (int i = 6; i >= 0; i--)
		{
			if (base[i] > helpnum1) {
				base[i] -= helpnum1;
				base[i] *= 2;
				base[i + 1]++;
			}
			else base[i] *= 2;
		}
		return base;
	}
	if (instructionNum == 1) {
		level++;
		base[7] *= 2;
		for (int i = 6; i >= 0; i--)
		{
			if (base[i] > helpnum1) {
				base[i] -= helpnum1;
				base[i] *= 2;
				base[i + 1]++;
			}
			else base[i] *= 2;
		}
		for (size_t i = 0; i < 7; i++)
		{
			if (base[i] != INT_MAX) {
				base[i]++;
				break;
			}
			else base[i] = 0;
		}
		return base;
	}
	if (instructionNum == 2) {
		level--;
		base[0] /= 2;
		for (size_t i = 1; i < 8; i++)
		{
			if (base[i] % 2 == 1) base[i - 1] += (helpnum1 + 1);
			base[i] /= 2;
		}
		return base;
	}
	if (instructionNum == 3) {
		for (size_t i = 0; i < 8; i++)
		{
			if (base[i] == 0) {
				base[i] = INT_MAX;
			}
			else {
				base[i]--;
				return base;
			}
		}
		return base;
	}
	if (instructionNum == 4) {
		for (size_t i = 0; i < 8; i++)
		{
			if (base[i] == INT_MAX) {
				base[i] = 0;
			}
			else {
				base[i]++;
				return base;
			}
		}
	}
}
int main()
{
	vector<ll> base(8);
	int num;
	cin >> num;
	for (size_t i = 0; i < num; i++)
	{
		int a;
		cin >> a;
		base = move(base, a);
	}
	string r = "";
	for (size_t i = 0; i < 8; i++)
	{
		r += ConvertToBits(base[7 - i]);
	}
	cout << level << "\n" << r;
}

// 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
Compilation error
exit status 1
main.cpp:10:16: error: 'INT_MAX' was not declared in this scope
   10 | int helpnum1 = INT_MAX / 2;
      |                ^~~~~~~
main.cpp:7:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    6 | #include <cmath>
  +++ |+#include <climits>
    7 | #include <vector>
main.cpp: In function 'std::string ConvertToBits(int)':
main.cpp:13:22: error: 'INT_MAX' was not declared in this scope
   13 |         ll divisor = INT_MAX;
      |                      ^~~~~~~
main.cpp:13:22: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
main.cpp: In function 'std::vector<long long int> move(std::vector<long long int>, char)':
main.cpp:56:40: error: 'INT_MAX' was not declared in this scope
   56 |                         if (base[i] != INT_MAX) {
      |                                        ^~~~~~~
main.cpp:56:40: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
main.cpp:78:43: error: 'INT_MAX' wa...