No older revisions available
No older revisions available
~cpp
#include <iostream>
using namespace std;
void judgeYundal();
void calanderoutput();
int addMonth[12] = {0,3,0,3,2,3,2,3,3,2,3,2}; // 월별 1일 위치 더해줘야 하는 날수
int lastDayOfMonth[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
int yearInput, monthInput, count = 0, dateNumber = 1 , locationOf1stDay, addm;
bool yundal;
int main()
{
cout << "연을 입력하십시오 :";
cin >> yearInput;
cout << "달을 입력하시오 :";
cin >> monthInput;
judgeYundal();
for (int x = 0 ; x < monthInput ; x++) // 1년 1일 위치
addm += addMonth[x];
if (yundal == true) {
locationOf1stDay = (addm + yearInput + count - 1 + 6) % 7; //
if ( monthInput > 2 )
locationOf1stDay++;
} else { // 각 년의 1일의 위치
locationOf1stDay = (addm + yearInput + count + 6 ) % 7; //
}
calanderoutput();
return 0;
}
void judgeYundal() // 윤달의 횟수와 여부를 판단
{
for (int i = 0 ; i <= yearInput ; i++)
{
if ( i%100 != 0 && i%4 == 0)
yundal = true;
else if ( i%100 == 0 && i%400 != 0)
yundal = false;
else if ( i%400 == 0 )
yundal = true;
else
yundal = false;
if (yundal == true)
count++;
}
}
void calanderoutput() // 달력의 출력
{
cout << "\t\t" << yearInput << "년\t" << monthInput << "월 달력\n\n";
cout << "일\t월\t화\t수\t목\t금\t토" << endl;
for (int j = 1 ; j<=6 ; j++)
{
for (int k = 0 ; k <= 6 ; k++)
{
if ( (j == 1 && k < locationOf1stDay) ||
dateNumber > lastDayOfMonth[monthInput-1] ||
(dateNumber == 29 && !yundal) ) {
cout << " \t";
} else {
cout << dateNumber << "\t";
dateNumber++;
}
}
cout << "\n";
}
}