54252023-05-17 11:48:00TortelliniJrTáblajátékcpp17Részben helyes 36/503ms3508 KiB

#include <iostream>
#include <vector>
#include <array>
#include <cmath>
#include <string>

using namespace std;

int main()
{
    int n, s, o, j;
	o = 0;
	s = 0;
    cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> j;
		switch (j)
		{
		case 0:
			s++;
			o *= 2;
			break;
		case 1:
			s++, o *= 2, o++;
			break;
		case 2:
			s--;
			o = o / 2;
			break;
		case 3:
			o--;
			break;
		case 4:
			o++;
			break;
		}
	}
	string t;
	if (o == 0)
	{
		t = "0";
	}
	while (o > 0)
	{
		t = to_string(o % 2) + t;
		o /= 2;
	}
	cout << s << endl;
	cout << t << endl;
}