728x90
반응형
첫번째 코드
나이별로 계산하는 방법을 알아보면 아래와 같다.
만 나이: 연도의 차이 + 생일전(0)/생일후(1)
세는 나이: 연도의 차이 +1
연 나이: 연도의 차이
이를 코드로 구성하면 된다.
import sys
input = sys.stdin.readline
birthday = list(map(int, input().split()))
today = list(map(int, input().split()))
a = 0
b = 0
c = 0
c = today[0] - birthday[0]
b = c + 1
a = c - 1
if today[1] > birthday[1]:
a += 1
elif today[1] == birthday[1]:
if today[2] >= birthday[2]:
a += 1
answer = [a, b, c]
for i in answer:
print(i)
통과:)
링크
programmers/백준/Bronze/16199. 나이 계산하기 at main · ornni/programmers
repository for recording Programmers Algorithm problem solving - ornni/programmers
github.com
반응형