데블 만
~cpp #include <iostream> #include <climits> using namespace std; void output(int , int); int deter_date(int, int); int lastdays(int, int); int how_much_days(int, int); int main() { int year, month; while (true) { cout << "를 : "; cin >> year; cout << " : "; cin >> month; if ( !year || !month ) break; if ( year <= 0 || year >INT_MAX || month <=0 || month>12) { cout << "못 ." << endl; continue; } output(year, month); } return 0; } void output(int year, int month) { int days = how_much_days(year, month); int date; if (year%400 != 0) date = deter_date(year%400, month); //(?) year%400 대 year 면 러... ? //400 므 year%400 . else date = deter_date(400, month); cout << "====================================================" << endl << "\t\t\t\t목\t\t" << endl; for ( int j=0 ; j<date ; j++) //를 만 빈 cout << "\t"; for ( int i=0 ; i<days ; i++) //1 days { if ( date > 6 ){ // 면 cout << endl; // date=0; // } cout << i+1 << "\t"; date++; //보는 } cout << endl << "====================================================" << endl; } int deter_date(int year, int month )// 는 (0 , 6 ) { if ( month == 0 ){ year--; month = 12; } else if ( year == 1 && month == 1) return 1; // 1 1는 부 return (lastdays(year,month) + deter_date(year, month-1)) % 7;// /* 며를 는 면 번 무 는 . 를 들 1 2 1 1 31 부 므 (31 + 1) % 7 == 4 목부 . */ } int lastdays(int year, int month)// 를 { int last; switch(month) { case 3: if ( year%4 == 0) { last = 29; if ( year%400 == 0 ) last = 29;// if ( year%4000 == 0 ) last = 28;// else if ( year%100 == 0 ) last = 28;// } else last = 28; break; case 5: case 7: case 10: case 12: last = 30; break; case 1: case 8: case 2: last = 31; break; case 4: case 6: case 9: case 11: last = 31; break; } return last; } int how_much_days(int year, int month) { int days; switch(month)// 를 { case 1: case 3: case 5: case 7: case 8: case 10: case 12: days = 31; break; case 2: if ( year%4 == 0) { days = 29; if ( year%400 == 0 ) days = 29;// if ( year%4000 == 0) days = 28;// else if ( year%100 == 0 ) days = 28;// } else// days = 28; break; case 4: case 6: case 9: case 11: days = 30; break; } return days; }