[백준/파이썬] 13773번 풀이

업데이트:



문제 정보


풀이

문제

The Olympic Games in Rio cannot have escaped your attention! 2016 is a summer Olympics year.

The modern summer Olympic Games were first held in 1896, and have been held at 4 yearly intervals since then, except during the two world wars (1914 to 1918 and 1939 to 1945). The next games are scheduled to be held in Tokyo in 4 years time.

입력 요약
Input will consist of a list of years, one per line, in the range 1860 to 2030 inclusive. The final year will be 0 – do not process that year.

출력 요약
Output is one line per year. The year is given followed by:

Summer Olympics - if the summer Olympic Games were held, or are scheduled to be held in that year.

Games cancelled - if the summer games should have been held but there was a war. …

코드

while True:
    n=int(input())
    if n==0:break
    if n%4!=0 or n<1896:r='No summer games'
    elif 1913<n<1919 or 1938<n<1946:r='Games cancelled'
    elif n>2020:r='No city yet chosen'
    else:r='Summer Olympics'
    print(n,r)

설명

핵심은 구현 관점에서 The Olympic Games in Rio cannot have escaped your attention! 2016 is a summer Olympics year. …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기