
import sys
s = list(range(1,21))
for _ in range(10):
a, b = map(int,sys.stdin.readline().split())
exc = list(s[a-1:b]) # s[5-1:10]
exc.reverse()
for i in range(len(exc)):
s[a-1+i] = exc[i] # exc[0] = s[5-1+0] / exc[1] = s[5-1+1]
print(' '.join(map(str, s)))
# 더 쉬운 버전
import sys
s = list(range(1, 21))
for _ in range(10):
a, b = map(int, sys.stdin.readline().split())
exc = s[a-1:b] # 1을 빼서 올바른 범위 설정
exc.reverse() # 역순으로 정렬
s[a-1:b] = exc # 원본 리스트에 반영
print(' '.join(map(str, s))) # 결과를 공백으로 구분하여 출력
* 문제를 잘 읽어야함!
여기서 순서를 거꾸로 하라고 했지 정렬하라고 하지는 않았음
> 나는 정렬로 이해해서 계속 sorted(reverse = true) 이걸로 해서 틀림,,
>> 순서만 바꾸는 거는 reverse()
'HELLO WORLD > BAEKJOON' 카테고리의 다른 글
| 백준 | 25304 영수증 (0) | 2025.01.18 |
|---|---|
| 백준 | 16340 제리와 톰 (0) | 2025.01.18 |
| 백준 | 1267 핸드폰 요금 (0) | 2025.01.17 |
| 백준 | 2754 학점계산 (0) | 2025.01.17 |
| 백준 | 10757 큰 수 A+B (0) | 2025.01.17 |