-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevel2_삼각달팽이_월간 코드 챌린지 시즌 1.cpp
45 lines (41 loc) · 1.04 KB
/
Level2_삼각달팽이_월간 코드 챌린지 시즌 1.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
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int arr[1001][1001] = { 0 };
vector<int> solution(int n) {
vector<int> answer;
arr[0][0] = 1;
int cnt = n, cntLength = n, Case = 1, i = -1, j = 0, num = 1;
while (true) {
if (cntLength == 0) break;
if (Case == 1) {
if (cnt == 0) { Case = 2; cnt = --cntLength; continue; }
arr[++i][j] = num++;
--cnt;
}
else if (Case == 2) {
if (cnt == 0) { Case = 3; cnt = --cntLength; continue; }
arr[i][++j] = num++;
--cnt;
}
else if (Case == 3) {
if (cnt == 0) { Case = 1, cnt = --cntLength; continue; }
arr[--i][--j] = num++;
--cnt;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= i; ++j) {
cout << arr[i][j] << ' ';
answer.push_back(arr[i][j]);
}
cout << '\n';
}
return answer;
}
int main() {
int n = 5;
solution(n);
return 0;
}