코딩로그
[백준/BOJ/C++] 9948번 Have you had your birthday yet? 본문
[문제]
Today it is 4th August. If you were born before 4th August (in whatever year you were born) then you have already had your 2007 birthday. If you were born after 4th August, you have not yet had your 2007 birthday. If you were born on 4th August, happy birthday! If you were born on 29th February unlucky, you do not have a birthday this year, as 2007 is not a leap year!
[입력]
Input will consist of a number of lines containing dates. All dates will be valid and no date will be repeated, so there will be no more than 365 lines. The format for a line will be one or two digits, a space, and the full name of a month. The name will begin with an upper case letter, and the other letters will be lower case. Input will be terminated by a line containing just 0 #.
[출력]
Output will consist of the word "Yes" if a person born on that date would have had their 2007 birthday by now, "No" if they would not, "Happy birthday" if the date is 4th August and "Unlucky" if the date is 29th February. The first letter on each output line is upper case, the rest are lower case.
[Source Code]
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int change(string input){
if(input == "January") return 1;
else if(input == "February") return 2;
else if(input == "March") return 3;
else if(input == "April") return 4;
else if(input == "May") return 5;
else if(input == "June") return 6;
else if(input == "July") return 7;
else if(input == "August") return 8;
else if(input == "September") return 9;
else if(input == "October") return 10;
else if(input == "November") return 11;
else if(input == "December") return 12;
}
int main() {
while(true){
int day, month;
string inputmonth;
cin >> day >> inputmonth;
if(day == 0 && inputmonth == "#") break;
month = change(inputmonth);
if(month < 8){
if(month == 2 && day == 29)
cout << "Unlucky\n";
else
cout << "Yes\n";
}
else if(month > 8)
cout << "No\n";
else{
if(day < 4)
cout << "Yes\n";
else if(day == 4)
cout << "Happy birthday\n";
else
cout << "No\n";
}
}
}
[결과 화면]
'YJ > C++' 카테고리의 다른 글
[백준/BOJ/C++] 13297번 Quick Estimates (0) | 2021.11.05 |
---|---|
[백준/BOJ/C++] 9947번 Coin tossing (0) | 2021.11.05 |
[백준/BOJ/C++] 9950번 Rectangles (0) | 2021.11.02 |
[백준/BOJ/C++] 4575번 Refrigerator Magnets (0) | 2021.11.02 |
[백준/BOJ/C++] 15238번 Pirates (0) | 2021.11.02 |