[BOJ]1476 날짜 계산

kangseonghee·2021년 8월 10일
0

Algorithm

목록 보기
9/12

풀이법

brute force 기법을 사용해서 하나 하나 증가시키며 비교한다.

import sys

input = sys.stdin.readline
E , S, M = map(int,input().split())
e, s, m = 1 , 1 , 1
year = 1
while(True):
    if e==E and s==S and m==M:
        print(year)
        break
    e += 1
    s += 1
    m += 1
    year += 1
    if e == 16 : e = 1
    if s == 29 : s = 1
    if m == 20 : m = 1 

잘못된 풀이(시간초과)

import sys

input = sys.stdin.readline
E , S, M = map(int,input().split())
year = 1
while(True):
    if year % 15 == E  :
        if year % 28 == S :
            if year % 19 == M:
                print(year)
                break        
    year = year + 1

0개의 댓글