⚡️algorithm

[완전탐색, 파이썬] 백준 1476. 날짜계산

남남이루 2022. 4. 29. 09:42

문제

이 나라의 규칙에 맞는 날짜계산 방식으로 year를 구해라

year이랑 e, s, m 간의 관계에 대한 식을 쉽게 표현할 수록 풀이가 쉬워진다.

2 try - success

import sys
sys.stdin = open('../DFS/in.txt', 'rt')
# input = sys.stdin.readline

e,s,m = map(int, input().split())

def DFS(year):
    global e
    res = year
    res2 = year
    res3 = year

    while res > 15:
        res -= 15
    if res != e:
        return False

    while res2 > 28:
        res2 -= 28
    if res2 != s:
        return False

    while res3 > 19:
        res3 -= 19
    if res3 != m:
        return False

    return year

y = 0

while True:
    if DFS(y) != False:
        print(y)
        break
    y += 1

3 try - success

import sys
sys.setrecursionlimit(10**6)
sys.stdin = open('../DFS/in.txt', 'rt')
# input = sys.stdin.readline

e,s,m = map(int, input().split())
def DFS(year):
    global e
    global s
    global m

    if (year-e) % 15 == 0 and (year-s) % 28 == 0 and (year-m) % 19 == 0:
        return True
    return False

y = 0
while True:
    if DFS(y) == True:
        print(y)
        break
    y+=1