-
[배열] 하 - 2920 음계 문제백준 Online Judge 2021. 8. 23. 18:31
2920번: 음계
다장조는 c d e f g a b C, 총 8개 음으로 이루어져있다. 이 문제에서 8개 음은 다음과 같이 숫자로 바꾸어 표현한다. c는 1로, d는 2로, ..., C를 8로 바꾼다. 1부터 8까지 차례대로 연주한다면 ascending, 8
www.acmicpc.net
문제 요약
- 난이도 : 하
- 문제 유형 : 배열, 구현
- 추천 풀이 시간 : 15분
- [문제 링크](https://www.acmicpc.net/problem/2920)
- 문제 해설
- 숫자 1~8까지 여러 개를 입력 받았을 때, ascending/descending/mixed로 분류하는 문제
- 입력 예시 : 1 2 3 4 5 6 7 8
- 출력 예시 : ascending
문제 풀이 코드
# 데이터를 입력 받는다. data_list = list(map(int, input().split(' '))) # 기본 초기값 설정 ascending = True descending = True # index=1부터 리스트의 길이 만큼 비교한다 for i in range(1, len(data_list)): # 오름차순인 경우 if data_list[i] > data_list[i-1]: descending = False # 내림차순인 경우 elif data_list[i] < data_list[i-1]: ascending = False if ascending: print('ascending') elif descending: print('descending') else: print('mixed')
입력: 2 5 19 4 2 6 9 8
결과: mixed
GitHub - DAWUNHAN/Algorithms-and-DataStructure: Algorithms and DataStructure with Python
Algorithms and DataStructure with Python. Contribute to DAWUNHAN/Algorithms-and-DataStructure development by creating an account on GitHub.
github.com
'백준 Online Judge' 카테고리의 다른 글
[백준] 1920 수 찾기 (0) 2021.08.26 [백준] 10930 SHA-256 (0) 2021.08.26 [백준] 5397 키로그 (0) 2021.08.25 [백준] 1874 스택 수열 (0) 2021.08.25 [백준] 2798 블랙잭 (0) 2021.08.23