다장조는 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인지 판별하는 프로그램을 작성하시오.
출처 : https://www.acmicpc.net/problem/2920
Mine:
정렬함수(sort) 이용
- 오름차순으로 정렬된 리스트 변수 생성
- 내림차순으로 정렬된 리스트 변수 생성
- if 오름차 ? ascending, 내림차 ? descending
NDB:
Boolean 이용, for문 통해 요소 하나씩 접근 비교
Mine
nums=list(map(int, input().split())) sortlist = sorted(nums) xsortlist = list(reversed(sortlist)) if sortlist == nums: print('ascending') elif nums == xsortlist: print('descending') else: print('mixed')
출처 : https://github.com/Gitgorithm/hyebinnn_Github/commit/51eba67fd826ce3cd803f1a8d899b68eb80bf665
NDB
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')
출처 : https://github.com/ndb796/Fast_Campus_Algorithm_Lecture_Notes/blob/master/Solutions/%5B01%5D_1.py