BOJ14499: 주사위 굴리기 작성일 2020-01-27 https://www.acmicpc.net/problem/14889 연휴동안 100문제 풀기 (6/100) 시뮬레이션 문제를, 잘 못푼다는거는 심각한 문제 생각한대로 구현하는걸 잘해야한다. 전치 후치 증감 연산을 함부로 쓰지 말자. 그냥 한줄 더쓰는게 낫다. 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586#include <bits/stdc++.h> using namespace std; class Dice { public: int T = 0; int B = 0; int E = 0; int W = 0; int N = 0; int S = 0; void north() { int _B = N; int _S = B; int _T = S; int _N = T; B=_B, S=_S, T=_T, N=_N; } void south() { int _B = S; int _N = B; int _T = N; int _S = T; B=_B, S=_S, T=_T, N=_N; } void east() { int _B = E; int _W = B; int _T = W; int _E = T; B=_B, W=_W, T=_T, E=_E; } void west() { int _B = W; int _E = B; int _T = E; int _W = T; B=_B, W=_W, T=_T, E=_E; } }; void copy(Dice& dice, int arr[][21], int sx, int sy) { if(arr[sx][sy]) dice.B = arr[sx][sy], arr[sx][sy] = 0; else arr[sx][sy] = dice.B; } int main() { ios::sync_with_stdio(false); int N, M, sx, sy, K, arr[21][21]; cin >> N >> M >> sx >> sy >> K; for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) cin >> arr[i][j]; Dice dice = Dice(); for(int i = 0; i < K; i++) { int cmd; cin >> cmd; if(cmd == 1) { if (sy == M-1) continue; dice.east(); sy++; copy(dice, arr, sx, sy); } else if(cmd == 2) { if (sy == 0) continue; dice.west(); sy--; copy(dice, arr, sx, sy); } else if(cmd == 3) { if (sx == 0) continue; dice.north(); sx--; copy(dice, arr, sx, sy); } else if(cmd == 4) { if (sx == N-1) continue; dice.south(); sx++; copy(dice, arr, sx, sy); } cout << dice.T << "\n"; } }