ë§Œë…„ë‹¬ë ¥ ¶
완성했당 *^^* ì•„ì§� 코드 쉽게 ì�´í•´í• 수 있ë�„ë¡� ê³ ì¹˜ë©´ ì¢‹ê² ë‹¤ê³ ì°½ì„ì�´í˜•ì�´ ì¶©ê³ í•¨ ã… ã… ë‹´ì—� 짤때는 깔금하게...
~cpp
#include<iostream>
using namespace std;
bool isYunYear(int x); // 윤년�지 여부를 �별
int monthDays(int x,int y); // 월� �수를 계산하는 함수
int main()
{
int year, month; // year,month는 ìž…ë ¥ë°›ì�€ ë…„,ì›”
cin >> year >> month; // year ì�€ ì•Œê³ ì‹¶ì�€ ë…„ë�„, month 는 ì•Œê³ ì‹¶ì�€ 달.
int yunYear4Year = year / 4;
int yunYear100Year = year / 100;
int yunYear400Year = year / 400;
int yunYearTotal = yunYear4Year - yunYear100Year + yunYear400Year;
int weekDay = (year + yunYearTotal) % 7; // (year+z)%7� 년� 1월� 요�
for(int i = 0 ; i < month-1 ; i++)
{
weekDay=( weekDay+monthDays(year,i+1)%7 ) %7; // ìž…ë ¥í•œ ì›”ì�˜ ìš”ì�¼ì�„ 구한다.
}
cout<<"ì�¼"<<"\t"<<"ì›”"<<"\t"<<"í™”"<<"\t"<<"수"<<"\t"<<"목"<<"\t"<<"금"<<"\t"<<"í† "<<endl;
for(i=0; i<weekDay; i++)
cout << " \t";
for(i=0 ; i<monthDays(year,month); i++)
{
cout << i+1 << "\t";//ë‚ ì§œë¥¼ 순서대로 ì¶œë ¥
weekDay = weekDay+1;
if(weekDay==7)//0~6 ì�„ ì�¼~í† ë�¼ê³ í–ˆì�„때 í† ìš”ì�¼ê°’ì�„ ìž…ë ¥í•˜ë©´ 한칸 뛰운다.
{
weekDay=0;
cout << endl;
}
}
cout<<endl;
return 0;
}
bool isYunYear(int x)//윤년� 계산하는 함수
{
if(x%4 ==0)
{
if(x%100 ==0)
{
if(x%400 ==0)
return true;
return false;
}
return true;
}
return false;
}
int monthDays(int x, int y)//월� �수를 계산하는 함수
{
if( y==1 || y==3 || y==5 || y==7 || y==8 || y== 10 || y==12)
return 31;//1월 3월....� 31� 까지 있다.
else if( y==2)//2월� 29� �는 28�...
{
if(isYunYear(x)==true)
return 29;
return 28;
}
else//그외 월� 모� 30�
return 30;
}
함수를 하나� 사용. 코드�해를 �가시키기위해서...
~cpp
#include<iostream>
using namespace std;
bool isYunYear(int x); // 윤년�지 여부를 �별
int monthDays(int x,int y); // 월� �수를 계산하는 함수
int getMonthWeekDay(int x, int y);
int main()
{
int year, month; // year,month는 ìž…ë ¥ë°›ì�€ ë…„,ì›”
cin >> year >> month; // year ì�€ ì•Œê³ ì‹¶ì�€ ë…„ë�„, month 는 ì•Œê³ ì‹¶ì�€ 달.
int yunYear4Year = year / 4;
int yunYear100Year = year / 100;
int yunYear400Year = year / 400;
int yunYearTotal = yunYear4Year - yunYear100Year + yunYear400Year;
int weekDay = (year + yunYearTotal) % 7; // (year+z)%7� 년� 1월� 요�
for(int i = 0 ; i < month-1 ; i++)
{
getMonthWeekDay(weekDay,monthDays(year,i+1)%7); // ìž…ë ¥í•œ ì›”ì�˜ ìš”ì�¼ì�„ 구한다.
}
cout<<"ì�¼"<<"\t"<<"ì›”"<<"\t"<<"í™”"<<"\t"<<"수"<<"\t"<<"목"<<"\t"<<"금"<<"\t"<<"í† "<<endl;
for(i=0; i<weekDay; i++)
cout << " \t";
for(i=0 ; i<monthDays(year,month); i++)
{
cout << i+1 << "\t";//ë‚ ì§œë¥¼ 순서대로 ì¶œë ¥
weekDay = weekDay+1;
if(weekDay==7)//0~6 ì�„ ì�¼~í† ë�¼ê³ í–ˆì�„때 í† ìš”ì�¼ê°’ì�„ ìž…ë ¥í•˜ë©´ 한칸 뛰운다.
{
weekDay=0;
cout << endl;
}
}
cout<<endl;
return 0;
}
bool isYunYear(int x)//윤년� 계산하는 함수
{
if(x%4 ==0)
{
if(x%100 ==0)
{
if(x%400 ==0)
return true;
return false;
}
return true;
}
return false;
}
int monthDays(int x, int y)//월� �수를 계산하는 함수
{
if( y==1 || y==3 || y==5 || y==7 || y==8 || y== 10 || y==12)
return 31;//1월 3월....� 31� 까지 있다.
else if( y==2)//2월� 29� �는 28�...
{
if(isYunYear(x)==true)
return 29;
return 28;
}
else//그외 월� 모� 30�
return 30;
}
int getMonthWeekDay(int x, int y)
{
return x=(x+y) %7;
}
곽세환,조재화









