Memo
로직 설명
•
temp 배열에 연산 수행한 값을 저장하고, 수행 후 원래 배열로 옮깁니다.
자료 구조
PASS
코드 설명
•
#define FOR 형태 사용 이유
→ 각 연산을 모듈화 하지 않고 싶었는데, 이중 포문이 너무 많아서 코드가 지저분해지는 것이 싫어서 사용했습니다. 
→ 대회에서는 for(int i = 0 ; i < n ; j++) 와 같은 실수를 방지하고자 사용한다 합니다.(증감식에 i가 아니라 j가 들어감)
어려웠던 부분 
•
연산 5, 6에서 반복문을 돌리는 로직이 어려웠습니다.
개선할 부분 
•
반복적인 작업을 수행할 때는 시작 위치를 우선적으로 생각하기.
Code
제출 날짜
@4/10/2021 
메모리
2096 KB
시간
8 ms
#include <iostream>
#include <algorithm>
#include <cstring>
#define endl "\n"
#define FOR(i, n) for(int i = 0 ; i < n ; i++)
#define D_FOR(i, n) for(int i = n ; i >= 0 ; i--)
#define R_FOR(i, s, n) for (int i = s ; i < n ; i++)
int N, M, R, OP;
int g_map[101][101];
int tmp[101][101];
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};
void input_faster()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
}
void input()
{
	input_faster();
	std::cin >> N >> M >> R;
	FOR(i, N)
	FOR(j, M) std::cin >> g_map[i][j];
}
void rotate()
{
	if (OP == 1)
	{
		FOR(i, N)
		FOR(j, M) tmp[N - i - 1][j] = g_map[i][j];
	}
	else if (OP == 2)
	{
		FOR(i, N)
		FOR(j, M) tmp[i][M - j - 1] = g_map[i][j];
	}
	else if (OP == 3)
	{
		FOR(j, M)
		D_FOR(i, N) tmp[j][N - 1 - i] = g_map[i][j];
		std::swap(N, M);
	}
	else if (OP == 4)
	{
		FOR(i, N)
		FOR(j, M) tmp[M - 1 - j][i] = g_map[i][j];
		std::swap(N, M);
	}
	else if (OP == 5)
	{
		int h_N = N / 2, h_M = M / 2;
		int s_y = 0, s_x = 0, n_y, n_x;
		FOR(k, 4)//direction
		{
		n_y = dy[k] * h_N, n_x = dx[k] * h_M;
		R_FOR(i, s_y, s_y + h_N)
		R_FOR(j, s_x, s_x + h_M) tmp[i + n_y][j + n_x] = g_map[i][j];
		s_y = s_y + dy[k] * h_N;
		s_x = s_x + dx[k] * h_M;
		}
	}
	else if (OP == 6)
	{
		int h_N = N / 2, h_M = M / 2;
		int s_y = 0, s_x = 0, n_y, n_x;
		FOR(k, 4)//direction
		{
		int dir = (5 - k) % 4;
		n_y = dy[dir] * h_N, n_x = dx[dir] * h_M;
		R_FOR(i, s_y, s_y + h_N)
		R_FOR(j, s_x, s_x + h_M) tmp[i + n_y][j + n_x] = g_map[i][j];
		s_y = s_y + dy[dir] * h_N;
		s_x = s_x + dx[dir] * h_M;
		}
	}
	std::memcpy(g_map, tmp, sizeof(g_map));
}
void solve()
{
	while (R--)
	{
		std::cin >> OP;
		rotate();
	}
}
void print_val()
{
	FOR(i, N){
	FOR(j, M) std::cout << g_map[i][j] << " ";
	std::cout << endl;}
}
int main()
{
	input();
	solve();
	print_val();
	return (0);
}
C++
복사



