BOJ/백준-1476-python

cosmos·2021년 3월 19일
3
post-thumbnail

문제📖

풀이🙏

  • 준규는 이상한곳에 산다.
  • 첫째 줄에 세 수 E, S, M이 주어진다.
  • (1 ≤ E ≤ 15, 1 ≤ S ≤ 28, 1 ≤ M ≤ 19)
  • 첫째 줄에 E S M으로 표시되는 가장 빠른 연도를 출력한다.
  • 1 1 1 은 항상 1이기 때문에, 정답이 음수가 나오는 경우는 없다.
    -> while 반복문 + 증감표현식 변수 + if 조건문으로 구현하였다.
    -> if earth == E and sun ==S and moon == M 보다는 python coding convention PEP8에 따른 all 사용이 더 좋다.

코드💻

# boj 1476 : 날짜 계산 python
import sys

def date_calculation(E, S, M): # (1 ≤ E ≤ 15, 1 ≤ S ≤ 28, 1 ≤ M ≤ 19)
    cnt = 1

    while True:
        earth = cnt % 15

        if earth is 0:
            earth = 15

        sun = cnt % 28

        if sun is 0:
            sun = 28

        moon = cnt % 19

        if moon is 0:
            moon = 19

        if all((earth is E, sun is S, moon is M)):
            break
        else:
            cnt += 1
            
    return cnt

E, S, M = map(int,sys.stdin.readline().split())  # 지구, 태양, 달
            
print(date_calculation(E, S, M))

결과😎

출처 && 깃허브📝

https://www.acmicpc.net/problem/1476
github

0개의 댓글