https://www.acmicpc.net/problem/2920
nums = [int(x) for x in input().split()]
if nums == sorted(nums):
print("ascending")
elif nums == sorted(nums, reverse=True):
print("descending")
else:
print("mixed")
위에서 풀이에서 시간을 줄여보자.
nums = [int(x) for x in input().split()]
prev = nums[0]
is_ascending = True
is_descending = True
is_mixed = False
for i in range(1, len(nums)):
if prev < nums[i]:
is_descending = False
elif prev > nums[i]:
is_ascending = False
prev = nums[i]
if is_ascending is False and is_descending is False:
is_mixed = True
break
if is_ascending:
print("ascending")
elif is_descending:
print("descending")
elif is_mixed:
print("mixed")
a = list(map(int, input().split(' ')))
ascending = True
descending = True
for i in range(1, 8):
if a[i] > a[i-1]:
descending = False
elif a[i] < a[i-1]:
ascending = False
if ascending:
print("ascending")
elif descending:
print("descending")
else:
print("mixed")
>>> '3 2 1'.split()
['3', '2', '1']
>>> '3 2 1'.split(' ')
['3', '', '', '', '2', '', '1']
>>>