缔造者
题目描述 Description
我们经常需要使用日历,所以需要一个能生成日历的程序。
先要求你写一个程序,只需要输入年份,就能生成正确的日历。
输入描述 Input Description
输入包含多组测试数据。每组输入一个整数Y(1800<=Y<=2100),表示公元年份。
输出描述 Output Description
对于每组输入,输出对应的日历本。选中下面的输出样例查看具体的输出格式,注意空格的输出。
样例输入 Sample Input
2010
样例输出 Sample Output
2010 January February March Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 1 2 3 4 5 6 3 4 5 6 7 8 9 7 8 9 10 11 12 13 7 8 9 10 11 12 13 10 11 12 13 14 15 16 14 15 16 17 18 19 20 14 15 16 17 18 19 20 17 18 19 20 21 22 23 21 22 23 24 25 26 27 21 22 23 24 25 26 27 24 25 26 27 28 29 30 28 28 29 30 31 31 April May June Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 1 1 2 3 4 5 4 5 6 7 8 9 10 2 3 4 5 6 7 8 6 7 8 9 10 11 12 11 12 13 14 15 16 17 9 10 11 12 13 14 15 13 14 15 16 17 18 19 18 19 20 21 22 23 24 16 17 18 19 20 21 22 20 21 22 23 24 25 26 25 26 27 28 29 30 23 24 25 26 27 28 29 27 28 29 30 30 31 July August September Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 1 2 3 4 5 6 7 1 2 3 4 4 5 6 7 8 9 10 8 9 10 11 12 13 14 5 6 7 8 9 10 11 11 12 13 14 15 16 17 15 16 17 18 19 20 21 12 13 14 15 16 17 18 18 19 20 21 22 23 24 22 23 24 25 26 27 28 19 20 21 22 23 24 25 25 26 27 28 29 30 31 29 30 31 26 27 28 29 30 October November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 1 2 3 4 3 4 5 6 7 8 9 7 8 9 10 11 12 13 5 6 7 8 9 10 11 10 11 12 13 14 15 16 14 15 16 17 18 19 20 12 13 14 15 16 17 18 17 18 19 20 21 22 23 21 22 23 24 25 26 27 19 20 21 22 23 24 25 24 25 26 27 28 29 30 28 29 30 26 27 28 29 30 31 31
朱小川在2021-06-17 20:54:27追加了内容
ding
朱小川在2021-06-18 12:12:25追加了内容
我顶
朱小川在2021-06-18 18:33:51追加了内容
再顶
朱小川在2021-06-19 17:23:38追加了内容
ding
初级天翼
#include<stdio.h>
#include<string.h>
int rili[200];
int monthnumber[12]={31,28,31,30,31,30,31,31,30,31,30,31};
char skr[100]="Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa";
int insert(int year,int month);
int getweek(int year,int month,int day);
int main(){
int year,day,week,number,i;
while(scanf("%d",&year)!=EOF){
if(year%4==0&&year%100!=0||year%400==0){
monthnumber[1]=29;
}else{
monthnumber[1]=28;
}
printf(" %d ",year);
printf("\n\n");
puts(" January February March ");
puts(skr);
memset(rili,0,sizeof(rili));
for(i=1;i<=3;i++){
insert(year,i);
}
for(i=1;i<=126;i++){
rili[i-1]>0?printf("%2d",rili[i-1]):printf(" ");
if(i%21==0)
putchar(10);
else if(i%7==0)
printf(" ");
else
putchar(' ');
}
puts(" April May June ");
puts(skr);
memset(rili,0,sizeof(rili));
for(i=4;i<=6;i++){
insert(year,i);
}
for(i=1;i<=126;i++){
rili[i-1]>0?printf("%2d",rili[i-1]):printf(" ");
if(i%21==0)
putchar(10);
else if(i%7==0)
printf(" ");
else
putchar(' ');
}
puts(" July August September ");
puts(skr);
memset(rili,0,sizeof(rili));
for(i=7;i<=9;i++){
insert(year,i);
}
for(i=1;i<=126;i++){
rili[i-1]>0?printf("%2d",rili[i-1]):printf(" ");
if(i%21==0)
putchar(10);
else if(i%7==0)
printf(" ");
else
putchar(' ');
}
puts(" October November December ");
puts(skr);
memset(rili,0,sizeof(rili));
for(i=10;i<=12;i++){
insert(year,i);
}
for(i=1;i<=126;i++){
rili[i-1]>0?printf("%2d",rili[i-1]):printf(" ");
if(i%21==0)
putchar(10);
else if(i%7==0)
printf(" ");
else
putchar(' ');
}
}
return 0;
}
int getweek(int year,int month,int day){
if(month==1||month==2){
year--;
month+=12;
}
int c=year/100;
int y=year-c*100;
int week=(c/4)-2*c+(y+y/4)+(13*(month+1)/5)+day-1;
while(week<0){
week+=7;
}
week%=7;
return week;
}
int insert(int year,int month){
int number=1;
int week,i;
week=getweek(year,month,1);
for(i=week+((month-1)%3)*7;i<126&&number<=monthnumber[month-1];i++){
if(i%7==0&&i!=week+((month-1)%3)*7)
i+=14;
rili[i]=number++;
}
return 0;
}
AC愉快
中级天翼
或者这个