1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
#include <iostream>
using namespace std;
int days(int year, int month)
{
int days, i;
for (i = 1; i < month; i++)
{
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12)
days = days + 31;
else if (i == 4 || i == 6 || i == 9 || i == 11)
days = days + 30;
else if (i == 2)
days = days + 28;
}
days = days + 365 * (year - 1980);
return days;
}
int leapyear(int year, int month)
{
int i;
i = (year - 1977) / 4;
if (year % 4 == 0 && month > 2)
{
i++;
}
return i;
}
int weekdays(int days)
{
int i;
i = days % 7;
return i;
}
void calendar(int year, int month, int week)
{
int i, j, k, d, cal[49] = {0};
char m[12][10] = { "January", "February", "March", "April", "May", "June", "July", "Agust","September", "Octorber", "November", "December" };
switch (month)
{
case 1: d = 31;
break;
case 2 :
{
if ((year % 4) == 0) d = 29;
else d = 28;
}
break;
case 3: d = 31;
break;
case 4: d = 30;
break;
case 5: d = 31;
break;
case 6: d = 30;
break;
case 7: d = 31;
break;
case 8: d = 31;
break;
case 9: d = 30;
break;
case 10: d = 31;
break;
case 11: d = 30;
break;
case 12: d = 31;
break;
}
cout << " < " << year << " " << m[month - 1] << " >" << endl;
cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;
cout << "----------------------------" << endl;
j = 1;
for (i = (week + 2) % 7; i < (d + (week + 2) % 7); i++)
{
cal[i] = j;
j++;
}
k = 0;
for (i = 0; i < 6; i++)
{
for (j = 0; j < 6; j++)
{
if (cal[k] == 0)
{
cout << " " << endl;
}
else
{
cout << cal[k] << " ";
}
k++;
}
cout << "\n---------------------------" << endl;
}
}
int main()
{
int year, month, total_days, week;
cout << "1980년 부터 2030년 사이의 연월을 입력하세요 (ex: 2011 5)" << endl;
cin >> year >> month;
if (year >= 1980 && year <= 2030 && month >= 1 && month <= 12)
{
cout << "입력하신 달은 " << year << "년 " << month << "월 입니다.\n" << endl;
total_days = days(year, month) + leapyear(year, month);
week = weekdays(total_days);
calendar(year, month, week);
}
else
{
cout << "범위를 벗어났습니다" << endl;
}
system("PAUSE");
return 0;
}
|