https://www.acmicpc.net/status?user_id=rndpqls999&problem_id=2920&from_mine=1
채점 현황
www.acmicpc.net
와 list의 슬라이싱에서 잘못해서 계속 틀렸던 거였다.
# BOJ_2920
melodys = list(map(int, input().split()))
pre_melody = melodys[0]
answer = 'dontknow'
# for melody in melodys[1:]:
# print(melody)
for melody in melodys[1:]:
if melody > pre_melody:
if answer == 'descending' or answer == 'mixed':
answer = 'mixed'
break
else:
answer = 'ascending'
elif melody < pre_melody:
if answer == 'ascending' or answer == 'mixed':
answer = 'mixed'
break
else:
answer = 'descending'
else:
answer = 'mixed'
break
pre_melody = melody
print(answer)
for melody in melodys[1:-1]:
라고 해서 틀린 건데, 헷갈렸던 부분을 짚어보자.
list = [1, 2, 3, 4, 5, 6, 7, 8] 일 때
list[1:-1] 와 list[1:] 의 차이
주의하자, -1은 뒤에서 두번째 수인 7이라는 것을.
sort를 이용한 간단한 풀이들이 있었다.
다음에는 노가다식으로 말고 도구를 사용해서 풀도록 해보자.
a = list(map(int, input().split()))
if a == sorted(a):
print('ascending')
elif a == sorted(a, reverse=True):
print('descending')
else:
print('mixed')
'Computer Science > Algorithm' 카테고리의 다른 글
[백준] 1920번 수 찾기, python (0) | 2023.01.06 |
---|---|
[백준] 나이순 정렬 10814, python (0) | 2023.01.06 |
[1단계] 백준 1152번 단어의 개수, python (0) | 2023.01.05 |
[백준] 브론즈4에서 한 달 티어 목표 (0) | 2023.01.05 |
코드업 1099번문제 - 개미 경로 찾기 (0) | 2022.06.22 |