BOJ/C++ 배열돌리기3 IamToday 2020. 3. 3. 14:23 #include #include #include #include using namespace std; int n, m; int a[102][102], b[102][102]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, r; cin >> n >> m >> r; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; } } for (int d = 0; d < r; d++) { int v; cin >> v; if (v == 1) { memset(b, 0, sizeof(b)); memcpy(b, a, sizeof(a)); //상하 반전 for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { a[i][j] = b[n - i + 1][j]; //swap(a[i][j], a[n - i + 1][ j]); } } } else if (v == 2) { memset(b, 0, sizeof(b)); memcpy(b, a, sizeof(a)); //좌우반전 for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { a[i][j] = b[i][m - j + 1]; //swap(a[i][ j], a[i][ m - j + 1]); } } } else if (v == 3) { memcpy(b, a, sizeof(b)); //맵 보존 memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { a[j][n - i + 1] = b[i][j]; } } swap(n, m); } else if (v == 4) { memcpy(b, a, sizeof(b)); //맵 보존 memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { a[m - j + 1][i] = b[i][j]; } } swap(n, m); } else if (v == 5) { memset(b, 0, sizeof(b)); memcpy(b, a, sizeof(a)); for (int i = 1; i <= n / 2; i++) { for (int j = 1; j <= m / 2; j++) { //1~4사분면을 서로 바꿈 (시계방향) a[i][j] = b[n / 2 + i][j]; a[i][m/2+j] = b[i][j]; a[n/2+i][m/2+j] = b[i][m/2+j]; a[n/2+i][j] = b[n / 2 + i][m/2+j]; } } } else if (v == 6) { memset(b, 0, sizeof(b)); memcpy(b, a, sizeof(a)); for (int i = 1; i <= n / 2; i++) { for (int j = 1; j <= m / 2; j++) { //1~4사분면을 서로 바꿈 //반시계방향 a[i][j] = b[i][m/2+j]; a[n/2+i][j] = b[i][j]; a[n / 2 + i][m/2+j] = b[n/2+i][j]; a[i][m/2+j] = b[n/2+i][m/2+j]; } } } /*cout << v << '\n'; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) cout << a[i][j] << ' '; cout << '\n'; } cout << '\n';*/ } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) cout << a[i][j] << ' '; cout << '\n'; } cout << '\n'; return 0; } 공유하기 게시글 관리 나는 오늘, 'BOJ > C++' 카테고리의 다른 글 개똥벌레 (0) 2020.03.03 달리기 (0) 2020.03.03 이동하기 (0) 2020.03.02 할로윈묘지 (0) 2020.03.02 단어의 개수 (0) 2020.03.02 'BOJ/C++' Related Articles 개똥벌레 달리기 이동하기 할로윈묘지