Last active
August 29, 2015 14:17
-
-
Save LusainKim/7078f7274a0e1884c997 to your computer and use it in GitHub Desktop.
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; | |
/* | |
input한 년도의 | |
13일의 금요일이 포함된 월을 찾아라! | |
조건 : 가장 짧은 코드 | |
1900년 1월 1일 : 월 | |
*/ | |
int main(){ | |
int year(0), first_day(0), now_month(0); | |
bool b_13_fri_month[12] = { false }, no_13(false); | |
cout << "년도를 입력해주세요 : "; | |
cin >> year; | |
while (!(1900 < year || year > 4000)) { cout << "다른 년도를 입력해주세요 : "; cin >> year; } | |
for (int i = 1900; i < year; ++i, first_day %= 7){ | |
if (((i % 4 == 0) && (i % 100 != 0)) || (i % 400 == 0)) first_day += 366; | |
else first_day += 365; | |
} | |
for (now_month = 0; now_month < 12; first_day %= 7){ | |
if ((first_day + 12) % 7 == 4) b_13_fri_month[now_month] = true; | |
switch (++ now_month){ | |
case 1: case 3: case 5: case 7: case 8: case 10: case 12: | |
first_day += 31; | |
break; | |
case 2: if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) | |
first_day += 29; | |
else first_day += 28; | |
break; | |
case 4: case 6: case 9: case 11: | |
first_day += 30; | |
break; | |
} | |
} | |
for (int i = 0; i < 12; i++){ | |
if (b_13_fri_month[i]) { | |
cout << i + 1 << "월은 13일의 금요일이 있다." << endl; | |
no_13 = true; | |
} | |
} | |
if (!no_13) cout << year << "년은 13일의 금요일이 없다!" << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment