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
|
#include <string>
#include <vector>
using namespace std;
enum Direction
{
DOWN,
RIGHT,
UP
};
vector<int> solution(int n) {
vector<int> answer;
int array[1001][1001] = { 0, };
int number = 0;
int roofNumber = n;
int index = 0;
int floor = -1;
int direction = DOWN;
while (roofNumber != 0)
{
for (int i = 0; i < roofNumber; i++)
{
switch (direction)
{
case DOWN:
floor++;
break;
case RIGHT:
index++;
break;
case UP:
floor--;
index--;
break;
}
number++;
array[floor][index] = number;
}
roofNumber--;
if (direction == UP)
direction = DOWN;
else
direction++;
}
floor = 1;
index = 1;
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= i; j++)
answer.push_back(array[i][j]);
}
return answer;
}
|
cs |
'프로그래머스 - 내 풀이 > 프로그래머스 Lv2' 카테고리의 다른 글
프로그래머스/H-Index (0) | 2022.12.07 |
---|---|
프로그래머스 / KAKAO BLIND RECRUITMENT / 오픈채팅방 (0) | 2022.02.11 |
프로그래머스 / Summer/Winter Coding(~2018) / 영어 끝말 잇기 (0) | 2020.09.08 |
프로그래머스 / Summer,Winter Coding(2019) / 멀쩡한 사각형 (0) | 2020.07.17 |
프로그래머스 / 스택,큐 / 주식 가격 (0) | 2020.07.17 |