본문 바로가기
알고리즘/그리디 알고리즘

1138 한 줄로 서기

by tryotto 2019. 6. 27.
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
#include <stdio.h>
 
int rst[15= { 0 };
 
int main() {
    int n;
    scanf("%d"&n);
 
    for (int i = 1; i <= n; i++) {
        int num;
        scanf("%d"&num);
 
        int idx = -1;
        for (int j = 0; j < n; j++) {            
            if (rst[j] == 0) {
                idx++;
            }
            if (idx == num) {
                rst[j] = i;
                break;
            }
        }
    }
 
    for (int i = 0; i < n; i++)
        printf("%d ", rst[i]);
}
cs


'알고리즘 > 그리디 알고리즘' 카테고리의 다른 글

1343 폴리노미오  (0) 2019.06.27
1783 병든 나이트  (0) 2019.06.27
2437 저울  (0) 2019.06.27
1080 행렬  (0) 2019.06.23
1541 잃어버린 괄호  (0) 2019.06.23