백준 1992 c++

magicdrill·2024년 3월 4일
0

백준 문제풀이

목록 보기
95/654

백준 1992 c++

#include <iostream>

using namespace std;

bool** paper;

int input(int lower, int upper)
{
	//cout << "input()" << endl;
	int A;

	while (1)
	{
		cin >> A;
		if (A >= lower && A <= upper)
		{
			break;
		}
		else
		{
			;
		}
	}

	return A;
}

void input_paper(int N)
{
	//cout << "input_paper()\n";
	int i, j;
	char temp[65];

	for (i = 0; i < N; i++)
	{
		cin >> temp;
		for (j = 0; j < N; j++)
		{
			if (temp[j] == '1')
			{
				paper[i][j] = 1;
			}
			else
			{
				paper[i][j] = 0;
			}
		}
	}

	/*for (i = 0; i < N; i++)
	{
		for (j = 0; j < N; j++)
		{
			cout << paper[i][j] << " ";
		}
		cout << "\n";
	}*/

	return;
}

void cut_paper(int A, int B, int C)
{
	bool cut = false;
	int i, j;
	bool temp = paper[A][B];

	for (i = A; i < A + C; i++)
	{
		for (j = B; j < B + C; j++)
		{
			if (paper[i][j] != temp)
			{
				cut = true;
				break;
			}
			else
			{
				;
			}
		}
		if (cut == true)
		{
			cut = true;
			break;
		}
		else
		{
			;
		}
	}
	if (cut == true)
	{
		cout << "(";
		cut_paper(A, B, C / 2);
		cut_paper(A, B + C / 2, C / 2);
		cut_paper(A + C / 2, B, C / 2);
		cut_paper(A + C / 2, B + C / 2, C / 2);
		cout << ")";
	}
	else//cout == false
	{
		if (temp == 0)
		{
			cout << "0";
		}
		else
		{
			cout << "1";
		}
	}

	return;
}

void find_result(int N)
{
	cut_paper(0, 0, N);

	return;
}

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int N, i;

	N = input(1, 64);
	paper = new bool* [N];
	for (i = 0; i < N; i++)
	{
		paper[i] = new bool[N];
	}
	input_paper(N);
	find_result(N);
	for (i = 0; i < N; i++)
	{
		delete[] paper[i];
	}
	delete[] paper;

	return 0;
}

0개의 댓글