끄적끄적 코딩
article thumbnail
728x90

다각형이 주어지고, 만드는 방법이 주어질 때 방법 중에서
만들 수 있는 개수와, 만드는 방법을 출력하는 문제입니다.

주어진 다각형을 정방향은 주어지므로 반대방향에 대해서 구합니다.
반대방향
오른쪽 = 왼쪽 ( 1 = 3 )
왼쪽 = 오른쪽 ( 3 = 1 )
위 = 아래 ( 2 = 4 )
아래 = 위 ( 4 = 2 )

그리고 뒤집혔으므로 reverse함수를 통해서 뒤집어 주었습니다.

그리고 방법으로 나온 것들을 한글자씩 당기면서
주어진 정방향과 그에 대한 반대방향과 비교를 하고
같은 경우 카운트를 증가해주고 값을 배열에 넣어두었습니다.
모든 반복을 끝냈을 때 카운트와 배열에 값들을 출력했습니다.

 

#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
	int n;
	int cycle;
	int count = 0;
	string s;
	string ori1 = "";
	string ori2 = "";
	string result[110];

	cin >> n;

	for (int i = 0; i < n; ++i) {
		char c;
		cin >> c;

		ori1 += c;
		ori2 += (c + 1) % 4 + 1 + '0';
	}
	reverse(ori2.begin(), ori2.end());

	cin >> cycle;

	while (cycle--) {
		s = "";
		for (int i = 0; i < n; ++i) {
			char c;
			cin >> c;

			s += c;
		}

		string temp = s;

		for (int i = 0; i < n; ++i) {
			if (temp == ori1 || temp == ori2) {
				result[count] = s;
				++count;
				break;
			}
			temp = temp.substr(1, temp.length()) + temp[0];
		}
	}

	cout << count << endl;

	for (int i = 0; i < count; ++i) {
		for (int j = 0; j < ori1.length(); ++j) {
			cout << result[i][j];
			if (j < ori1.length() - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}

	return 0;
}

 

검색 태그