https://github.com/cjk09083/Code
https://www.acmicpc.net/problem/1476
1476번: 날짜 계산
준규가 사는 나라는 우리가 사용하는 연도와 다른 방식을 이용한다. 준규가 사는 나라에서는 수 3개를 이용해서 연도를 나타낸다. 각각의 수는 지구, 태양, 그리고 달을 나타낸다. 지구를 나타
www.acmicpc.net
해답 1)
import sys
input = sys.stdin.readline
if __name__ == "__main__":
E, S, M = map(int,input().split())
e, s, m = 0, 0, 0
end = 1_000_000
for i in range(end):
if e == E and s == S and m == M:
print(i)
break
e += 1
if e > 15:
e = 1
s += 1
if s > 28:
s = 1
m += 1
if m > 19:
m = 1
- e, s, m 을 1 씩 늘려가며 조건을 만족하는 i값을 찾는다.
- 40ms
해답 2)
import sys
input = sys.stdin.readline
if __name__ == "__main__":
E, S, M = map(int,input().split())
end = 1_000_000
for i in range(1,end):
if (i-E)%15 == 0 and (i-S)%28 ==0 and (i-M)%19 == 0:
print(i)
break
- E, S, M의 주기를 이용해 조건을 만족하는 i 값을 찾는다.
- 36ms
'미래의 나를 위한 메모 > 코딩테스트' 카테고리의 다른 글
[230116] 백준 14500번 - 테트로미노 (Python) (2) | 2023.01.16 |
---|---|
[230113] 백준 1107번 - 리모컨 (Python) (0) | 2023.01.13 |
[230111] 백준 3085번 - 사탕게임 (Python) (0) | 2023.01.11 |
[230111] 백준 2309번 - 일곱난쟁이(Python) (0) | 2023.01.11 |
[230110] 백준 6558번 - 골드바흐의 추측 (Python) (0) | 2023.01.10 |