[SWEA/C++] 1961 숫자 배열 회전

Hanbi·2022년 7월 22일
0

Problem Solving

목록 보기
24/128
post-thumbnail
post-custom-banner

문제

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5Pq-OKAVYDFAUq&categoryId=AV5Pq-OKAVYDFAUq&categoryType=CODE&problemTitle=&orderBy=RECOMMEND_COUNT&selectCodeLang=ALL&select-1=2&pageSize=10&pageIndex=2

풀이


회전 규칙만 찾으면 됨!

180도, 270도는 90도 회전을 반복

코드

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int test_case;
	int T;

	cin >> T;
	for (test_case = 1; test_case <= T; ++test_case) {
		int N, tmp;
		int arr[7][7] = { 0, };
		int arr_90[7][7] = { 0, };
		int arr_180[7][7] = { 0, };
		int arr_270[7][7] = { 0, };

		cin >> N;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				cin >> tmp;
				arr[i][j] = tmp;
			}
		}

		//90도 회전
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				arr_90[j][(N - 1) - i] = arr[i][j];
			}
		}

		//180도 회전
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				arr_180[j][(N - 1) - i] = arr_90[i][j];
			}
		}

		//270도 회전
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				arr_270[j][(N - 1) - i] = arr_180[i][j];
			}
		}

		cout << "#" << test_case << endl;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				cout << arr_90[i][j];
			}
			cout << " ";
			for (int j = 0; j < N; j++) {
				cout << arr_180[i][j];
			}
			cout << " ";
			for (int j = 0; j < N; j++) {
				cout << arr_270[i][j];
			}
			cout << endl;
		}
	}

	return 0;
}
profile
👩🏻‍💻
post-custom-banner

0개의 댓글