728x90
반응형
주어진 숫자가 변속 조건에 맞으면 각 조건에 맞는 결과를 출력하는 문제이다.
Softeer - 현대자동차그룹 SW인재확보플랫폼
현대자동차에서는 부드럽고 빠른 변속이 가능한 8단 습식 DCT 변속기를 개발하여 N라인 고성능차에 적용하였다. 관련하여 SW 엔지니어인 당신에게 연속적으로 변속이 가능한지 점검할 수 있는 프
softeer.ai
테스트 케이스
[TC1]
입력 : 1 2 3 4 5 6 7 8
출력 : ascending
해결 과정
기본적인 결과로 mixed로 초기화를 해놓고, ascending이나 descending의 조건과 일치하면 해당 값으로 다시 초기화하는 방식으로 해결했다.
코드
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
result = 'mixed'
arr = list(map(int, input().split()))
if arr[0] == 1:
for idx, v in enumerate(arr):
if idx == 7 and v == 8:
result = 'ascending'
break
if idx+1 == v:
continue
else:
break
elif arr[0] == 8:
for idx, v in enumerate(arr):
if idx == 7 and v == 1:
result = 'descending'
break
if idx + v == 8:
continue
else:
break
print(result)
주석 처리
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
result = 'mixed' # 정답 mixed로 초기화
arr = list(map(int, input().split()))
if arr[0] == 1: # 첫 숫자가 1이면
for idx, v in enumerate(arr): # 숫자가 있는 동안
if idx == 7 and v == 8: # 마지막 숫자면
result = 'ascending' # ascending으로 초기화
break
if idx+1 == v: # 하나씩 증가하면 조건에 일치하는 중이므로 넘김
continue
else: # 위 조건이 아니면 mixed이므로 바로 종료
break
elif arr[0] == 8: # 첫 숫자가 8이면
for idx, v in enumerate(arr): # 숫자가 있는 동안
if idx == 7 and v == 1: # 마지막 숫자면
result = 'descending' # descending으로 초기화
break
if idx + v == 8: # 하나씩 증가하면 조건에 일치하는 중이므로 넘김
continue
else: # 위 조건이 아니면 mixed이므로 종료
break
print(result)
728x90
반응형