python/알고리즘
[알고리즘] 백준 2920번, 음계, 1차원 배열 사용하기, python(11)
incastle
2019. 4. 13. 01:59
문제
다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8부터 1까지 차례대로 연주한다면 descending, 둘 다 아니라면 mixed 이다. 연주한 순서가 주어졌을 때, 이것이 ascending인지, descending인지, 아니면 mixed인지 판별하는 프로그램을 작성하시오.
뭔가 문제가 복잡하게 적혔다.
number = list(map(str, input().split(' ')))
ascending_count = 0
descending_count = 0
for i, name in enumerate(number):
if str(i+1) == name:
ascending_count += 1
if int(i) + int(name) == 8:
descending_count += 1
if ascending_count == 8:
print('ascending')
if descending_count == 8:
print('descending')
if ascending_count != 8 and descending_count != 8:
print('mixed')
enumerate를 사용하고 싶어서 깝쳐봤다.
사실 훨씬 더 숏코딩이 가능하오니..
mus = input()
if mus == '1 2 3 4 5 6 7 8':
print("ascending")
elif mus == '8 7 6 5 4 3 2 1':
print("descending")
else:
print("mixed")
숏코딩이 장땡이다...