[BOJ] 1022 소용돌이 예쁘게 출력하기

Time Lapse : 44min 52sec

1022.cpp

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <vector>
using namespace std;
long long MAP[50][5];
int main(void) {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
r1 += 5000;
r2 += 5000;
c1 += 5000;
c2 += 5000;
long long move = 1;
long long use_moved = move;
long long max = 0;
bool flag = true;
int x = 5000;
int y = 5000;
for(long long input = 1; input <= 10001*10001; input++){
if(r1<=y&&y<=r2 && c1<=x&&x<=c2) {
MAP[y - r1][x - c1] = input;
max = max < input ? input : max;
}
if(move%2==1){
if(flag){
++x;
--use_moved;
}
else{
--y;
--use_moved;
}
}
else{
if(flag){
--x;
--use_moved;
}
else{
++y;
--use_moved;
}
}
if(use_moved==0){
if(flag){
flag = false;
use_moved = move;
}
else{
++move;
flag = true;
use_moved = move;
}
}
}
int cnt = 0;
while(max>=10){
max /= 10;
++cnt;
}
for(int i=0;i<=r2-r1;i++){
for(int j=0;j<=c2-c1;j++){
int space = cnt;
int temp = MAP[i][j];
while(temp>=10){
--space;
temp /= 10;
}
for(int k=0;k<space;k++)
cout<<" ";

cout<<MAP[i][j];
if(j!=c2-c1)
cout<<" ";
}
cout<<endl;
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/23/PS/BOJ/1022/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.