문제 링크입니다: www.acmicpc.net/problem/16199
16199번: 나이 계산하기
첫째 줄에 어떤 사람이 태어난 연도, 월, 일이 주어진다. 생년월일은 공백으로 구분되어져 있고, 항상 올바른 날짜만 주어진다. 둘째 줄에 기준 날짜가 주어진다. 기준 날짜도 공백으로 구분되어
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
typedef struct | |
{ | |
int year, month, day; | |
}Date; | |
void printManAge(Date birth, Date current) | |
{ | |
int age = current.year - birth.year; | |
if (current.month < birth.month) | |
{ | |
age--; | |
} | |
if (current.month == birth.month) | |
{ | |
if (current.day < birth.day) | |
{ | |
age--; | |
} | |
} | |
cout << age << "\n"; | |
} | |
void printSeNeunAge(Date birth, Date current) | |
{ | |
int age = current.year - birth.year + 1; | |
cout << age << "\n"; | |
} | |
void printYeonAge(Date birth, Date current) | |
{ | |
int age = current.year - birth.year; | |
cout << age << "\n"; | |
} | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
Date birthDate, currentDate; | |
cin >> birthDate.year >> birthDate.month >> birthDate.day; | |
cin >> currentDate.year >> currentDate.month >> currentDate.day; | |
printManAge(birthDate, currentDate); | |
printSeNeunAge(birthDate, currentDate); | |
printYeonAge(birthDate, currentDate); | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 16486번 운동장 한 바퀴 (0) | 2021.03.24 |
---|---|
백준 16431번 베시와 데이지 (0) | 2021.03.24 |
백준 16017번 Telemarketer or not? (0) | 2021.03.23 |
백준 15963번 CASIO (0) | 2021.03.23 |
백준 15921번 수찬은 마린보이야!! (0) | 2021.03.22 |