반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #define rep(i,n) for(int i=1;i<=n;i++) using namespace std; int n, m, r; int arr[302][302], temp[302][302]; void rotate() { int start = 1; int n_copy = n; int m_copy = m; while (start < n_copy && start < m_copy) { // 상 하 for (int i = start; i <= m_copy; i++) { arr[start][i] = temp[start][i + 1]; arr[n_copy][i] = temp[n_copy][i - 1]; } // 좌 우 for (int i = start; i <= n_copy; i++) { if(i > start) arr[i][start] = temp[i - 1][start]; if(i < n_copy) arr[i][m_copy] = temp[i + 1][m_copy]; } // 사각형 크기 줄이고 계속 start++; m_copy--; n_copy--; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> r; rep(i, n) { rep(j, m) cin >> temp[i][j]; } rep(i, r) { rotate(); rep(i, n) { rep(j, m) temp[i][j] = arr[i][j]; } } rep(i, n) { rep(j, m) cout << arr[i][j] << ' '; cout << '\n'; } } | cs |
반응형