https://www.acmicpc.net/problem/2920
list = list(map(int, input().split()))
# print(list)
if list[0] - list[1] == -1:
print("ascending")
elif list[0] - list[1] == 1:
print("descending")
else:
print("mixed")
요소를 뺐을 때가 아니라 더 보편적으로 쓸 수 있도록 코드를 수정하자.
틀린 코드는 아니지만 좀 더 나은 답안이 있다.
a = list(map(int, input().split()))
if a == sorted(a):
print('ascending')
elif a == sorted(a, reverse=True):
print('descending')
else:
print('mixed')
sorted()함수는 오름차순 또는 내림차순으로 정렬된 값을 반환한다.(리스트의 원본 값은 그대로 유지된다.)
오름차순의 경우:
sorted(리스트 명)
내림차순의 경우:
sorted(리스트 명, reverse = True)
역순으로 입력한 값은 내림차순으로 정렬해도 입력한 값과 똑같이 정렬된다.