김태진 ¶
// // main.cpp // Calender // // Created by 김 태진 on 12. 1. 10.. // Copyright (c) 2012년 __MyCompanyName__. All rights reserved. // #include <stdio.h> int isLeapYr(int yr); int isThirtyOne(int mth); int main() { int month,day=1,myYear,date=1,monthEndDate; int i; int Max; scanf("%d",&myYear); if(isLeapYr(myYear)==1){ Max=366; }else{ Max=365; } for(i=1;i<myYear;i++){ if(isLeapYr(i-1)==1&&i!=1){ day+=2; }else{ day++; } //day 0 == 일 } day%=7; for(month=1;month<=12;month++){ date=1; if(isThirtyOne(month)==1){ monthEndDate=31; }else{ monthEndDate=30; if(month==2){ monthEndDate=28; if(isLeapYr(myYear)==1){ monthEndDate=29; } } } printf("\n%d월\n",month);//몇월 printf("일\t월\t화\t수\t목\t금\t토\n"); for(i=0;i<day;i++){ printf("\t"); } for(;date<=monthEndDate;date++){ printf("%d\t",date); if(i%7==6){ printf("\n"); } i++; } day=i%7; } return 0; } int isLeapYr(int yr){ int flag=0; if(yr%4==0){ flag=1;//1이면 윤년 if(yr%100==0){ flag=0; if(yr%400==0){ flag=1; } } } return flag; } int isThirtyOne(int mth){ if(mth==1||mth==3||mth==5||mth==7||mth==8||mth==10||mth==12){ return 1; }else{ return 0; } }
이민규 ¶
int Calculate_Days(int year){
year--;
return (year*365)+(year/4)-(year/100)+(year/400);
}return (year*365)+(year/4)-(year/100)+(year/400);
void PrintCal(int 년도,int 시작요일, bool 윤년){
int 월시작요일= 시작요일;
for(int 달=1; 달<13; 달++){
}for(int 달=1; 달<13; 달++){
printf("%d년 %d월\n", 년도, 달);
printf("월\t화\t수\t목\t금\t토\t일\n");
for(int i=0; i<월시작요일; i++) printf("\t");
for(int 날짜=1; ; 날짜++){
}printf("월\t화\t수\t목\t금\t토\t일\n");
for(int i=0; i<월시작요일; i++) printf("\t");
for(int 날짜=1; ; 날짜++){
printf("%d\t", 날짜);
if((날짜+월시작요일)%7 ==0) printf("\n");
if((달== 1)||(달==3)||(달==5)||(달==7)||(달==8)||(달==10)||(달==12)){
else if(달== 2){
else
}if((날짜+월시작요일)%7 ==0) printf("\n");
if((달== 1)||(달==3)||(달==5)||(달==7)||(달==8)||(달==10)||(달==12)){
if(날짜== 31){
}printf("\n");
월시작요일= (월시작요일+날짜)%7;
break;
}월시작요일= (월시작요일+날짜)%7;
break;
else if(달== 2){
if(윤년== true){
else
}if(날짜== 29){
printf("\n");
월시작요일= (월시작요일+날짜)%7;
break;
}
}printf("\n");
월시작요일= (월시작요일+날짜)%7;
break;
}
else
if(날짜== 28){
printf("\n");
월시작요일= (월시작요일+날짜)%7;
break;
}
printf("\n");
월시작요일= (월시작요일+날짜)%7;
break;
}
else
if(날짜== 30){
printf("\n");
월시작요일= (월시작요일+날짜)%7;
break;
}
월시작요일= (월시작요일+날짜)%7;
break;
}
void main(){
int 년도;
bool 윤년= false;
scanf("%d", &년도);
int 지난날수= Calculate_Days(년도);
int 시작요일=지난날수%7;
if((년도%4== 0)&& (년도%100!= 0))
}bool 윤년= false;
scanf("%d", &년도);
int 지난날수= Calculate_Days(년도);
int 시작요일=지난날수%7;
if((년도%4== 0)&& (년도%100!= 0))
윤년= true;
PrintCal(년도, 시작요일, 윤년);김수경 ¶
#include <iostream> using namespace std; void printYear(int year); void printHeader(int year, int month); void printMonth(int year, int month); int accumulatedDays(int year, int month); int numberOfDays(int year, int month); int isLeapYear(int year); int main(){ int year; cin>>year; printYear(year); return 0; } void printYear(int year){ for(int i = 1; i <= 12; i++){ printHeader(year, i); printMonth(year, i); } } void printHeader(int year, int month){ cout<<endl; cout<<"\t\t\t"<<year<<"년 "<<month<<"월"<<endl<<endl; cout<<"월\t화\t수\t목\t금\t토\t일"<<endl; } void printMonth(int year, int month){ int startDay = accumulatedDays(year, month) % 7; for(int i = 1; i <= startDay; i++){ cout<<"\t"; } for(int i = 1; i <= numberOfDays(year, month); i++){ cout<<i<<"\t"; if((i + startDay) % 7 == 0){ cout<<endl; } } cout<<endl; } int accumulatedDays(int year, int month){ int sum = 0; if(year >= 1){ sum = (year-1) * 365; for(int i = 1; i < year; i++){ sum += isLeapYear(i); } for(int i = 1; i < month; i++){ sum += numberOfDays(year, i); } } return sum; } int numberOfDays(int year, int month){ switch(month){ case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: return 28 + isLeapYear(year); } } int isLeapYear(int year){ return (year % 400 == 0) || ((year % 100 != 0) && (year % 4 == 0)); }