문제 링크입니다: https://programmers.co.kr/learn/courses/33/lessons/1857
COS Pro 2급 Python 모의고사 - 공항 방문객
XX 공항에서 N 일 동안 매일 공항 방문객 수를 조사했습니다. 이때, 가장 많은 방문객 수와 두 번째로 많은 방문객 수의 차이를 구하려고 합니다. 단, 방문객의 수가 같은 날은 없다고 가정합니다.
programmers.co.kr
회사에서 COS Pro 1급을 따면 상금을 준다고 해서 재미로 2급까지 풀어봤습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def func_a(arr, n): | |
ret = [] | |
for x in arr: | |
if x != n: | |
ret.append(x) | |
return ret | |
def func_b(a, b): | |
if a >= b: | |
return a - b | |
else: | |
return b - a | |
def func_c(arr): | |
ret = -1 | |
for x in arr: | |
if ret < x: | |
ret = x | |
return ret | |
def solution(visitor): | |
max_first = func_c(visitor) | |
visitor_removed = func_a(visitor, max_first) | |
max_second = func_c(visitor_removed) | |
answer = func_b(max_first, max_second) | |
return answer |

개발환경: Programmers IDE
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'Python > COS Pro 2급 Python 모의고사' 카테고리의 다른 글
[Programmers] 키가 K보다 큰 사람 (0) | 2022.05.12 |
---|---|
[Programmers] 개구리 (0) | 2022.05.12 |
[Programmers] 학점 계산 (0) | 2022.05.12 |
[Programmers] 총점 (0) | 2022.05.12 |
[Programmers] n부터 m까지 자연수의 합 (0) | 2022.05.12 |