728x90
풀이
첫째 줄에 세 정수 A, B, C가 공백으로 구분도이어 주어진다.
이 때 두 번째로 큰 정수를 출력하면 된다.
내가 좋아하는 if문으로 풀 수는 있는데, 이건 A, B, C 세 수여서 그나마 가능한 일이다.
무려 6가지의 상황을 고려해서 써야 하는데 수가 많아지면 힘들고 또 복잡해져서
이번에는 리스트를 활용해서 문제를 풀었다.
리스트 생성 > 오름/내림차순 정렬 > 리스트의 1번째 인덱스 (=2번째 요소) 출력
세 수여서 오름/내림 상관 없지만 수가 늘어나면 원래는 내림차순으로 풀어야 2번째 큰 요소를 찾을 수 있다.
오름차순 sort() / 내림차순 sort(reverse=True)
코드
A = list(map(int, input().split()))
A.sort(reverse=True)
print(A[1])
A, B, C = map(int, input().split())
if A >= B >= C :
print(B)
elif B >= C >= A :
print(C)
elif C >= A >= B :
print(A)
elif C >= B >= A :
print(B)
elif B >= A >= C :
print(A)
elif A >= C >= B :
print(C)
728x90