728x90
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
|
#include <iostream>
#include <algorithm>
using namespace std;
int n;
int map[20][20];
void rotate(){
int temp[20][20];
for(int y = 0; y <n; y++){
for(int x = 0; x < n; x++){
//temp[y][x] = map[x][n - y - 1]; //왼쪽으로 90도 회전
temp[y][x] = map[n-x-1][y]; //오른쪽으로 90
}
}
for(int y = 0; y < n; y++){
for(int x = 0; x <n; x++){
map[y][x] = temp[y][x];
}
}
}
int main(){
cin>>n;
for(int i = 0 ; i < n; i++) {
for(int j = 0 ; j < n; j++){
cin>>map[i][j];
}
}
rotate();
for(int i = 0 ; i < n; i++) {
for(int j = 0 ; j< n; j++){
cout<<map[i][j]<<" ";
}cout<<endl;
}
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
배열을 시계 방향으로 90도 회전하는 방법입니다.
728x90
'Software > 알고보면 쓸모있는 코딩스킬' 카테고리의 다른 글
[IntelliJ] 인텔리제이에서 Git Push / Pull 하고 master로 merge 하기 (0) | 2020.09.10 |
---|---|
공백을 포함한 문자열 입력 (0) | 2020.08.13 |
입력 개수가 주어지지 않을 때!? C++ EOF 사용법 (0) | 2020.08.01 |
C Language 파일 입출력 (0) | 2020.06.26 |
벡터 사이즈 정렬 (0) | 2020.04.17 |
댓글