기록하고 까먹지 말기

13417 본문

전공/백준

13417

yha97 2022. 12. 10. 00:30

날짜 : 2022. 12. 10

사용 언어 : python

 

문제

 

 

코드

import sys

t = int(sys.stdin.readline())
for _ in range(t):
    n = int(sys.stdin.readline())
    a = list(sys.stdin.readline().rstrip().split())
    res = []
    res.append(a[0])
    for i in range(1, n):
        if a[i] > res[0]: 
            res.append(a[i])
        else:
            res.insert(0, a[i])
    for i in res:
        print("%c"%i, end="")
    print()

 

 

풀이

- 입력 후 리스트 순서에 따라 맨 앞으로 이동할지, 맨 뒤로 이동할지 조건에 따라 삽입한다.

 

 

알게된 점

 

 

참고 사이트

 

'전공 > 백준' 카테고리의 다른 글

2805  (0) 2022.12.10
9237  (0) 2022.12.10
12845  (0) 2022.12.08
1753  (0) 2022.12.08
최단경로 응용문제(이코테) - 2  (0) 2022.12.07