※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※

 

이번에 볼 문제는 백준 6845번 문제인 Federal Voting Age이다.
문제는 아래 링크를 확인하자.

https://www.acmicpc.net/problem/6845 

 

6845번: Federal Voting Age

The input will consist of a number n (1 ≤ n ≤ 100) on a single line, indicating the number of birthdays to evaluate. Then, each of the following n lines, will be of the form y m d, where y is the year of a potential voter’s birth (0 ≤ y ≤ 2007),

www.acmicpc.net

예제를 참고하면, 주어진 날짜 중 1989년 2월 27일 또는 그 이전의 날짜의 경우 "Yes"를, 1989년 2월 28일 또는 그 이후의 날짜의 경우 "No"를 출력해 문제를 해결할 수 있음을 관찰할 수 있다.

 

조건문을 적절히 활용해 문제를 해결해주자.

 

"YES", "NO"가 아닌 "Yes", "No"를 출력해야 함에 유의하자. 즉, 대소문자에 유의해 구현해주자.

 

아래는 제출한 소스코드이다.

#include <iostream>
using namespace std;

int T;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> T;
	while (T--) {
		int y, m, d; cin >> y >> m >> d;
		if (y < 1989) cout << "Yes\n";
		else if (y > 1989) cout << "No\n";
		else if (m < 2) cout << "Yes\n";
		else if (m > 2) cout << "No\n";
		else if (d <= 27) cout << "Yes\n";
		else cout << "No\n";
	}
}
728x90

+ Recent posts