问题描述
- 求大神帮忙解决一下,谢啦
-
年历系统首先对于输入的任一年,能够给出该年每月的日期及实际周几的对应情况,并与实际的星期数垂直对齐,如下表所示(当输入2004时显示如下):
Input the year:2004
The calendar of the year 2004.
Januray 1 February 2
============================== ==============================
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
1 2 3 1 2 3 4 5 6 7
4 5 6 7 8 9 10 8 9 10 11 12 13 14
11 12 13 14 15 16 17 15 16 17 18 19 20 21
18 19 20 21 22 23 24 22 23 24 25 26 27 28
25 26 27 28 29 30 31 29
============================== ==============================
March 3 April 4
============================== ==============================
Sun Mon Tue Wed Thu Fri Sat Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 1 2 3
7 8 9 10 11 12 13 4 5 6 7 8 9 10
14 15 16 17 18 19 20 11 12 13 14 15 16 17
21 22 23 24 25 26 27 18 19 20 21 22 23 24
28 29 30 31 25 26 27 28 29 30
============================== ==============================功能要求 :
⑴ 输入任一年将显示出该年的所有月份日期,对应的星期,输出的格式如上表要求(注意闰年情况);
⑵ 输入任意日期(包括年、月、日,格式有yyy/mm/dd、dd/mm/yyyy、mm/dd/yyyy、和yyyy,mm,dd、mm,dd,yyyy、dd,mm,yyyy六种基本情况),要求能够显示出该日期是本年的哪一周,是星期几。
解决方案
你用的什么编程语言?
一般编程语言的日期类型都有方法取得年、月、日、星期几、第几周的功能,而且可以直接加1天的,根本不用处理闰年的。
解决方案二:
很简单的一个问题...
首先你可以写一个函数接收年份,然后在这个函数里边写上打印的格式,然后调用一个判断闰年的函数(也是接收一个年份),把其输出出来。怕麻烦的话你就一个个加。月份肯定是12,不会变,日期会根据闰年和月份改变,星期按照7天一循环就一直加吧、
解决方案三:
#include
#include
#define SIGN_WEEK 6
#define SIGN_YEAR 2000
void calendar(int week,int year) //显示日历
{
int month_day[14]={31,31,0,31,30,31,30,31,31,30,31,30,31,31};
char month_name[12][10]={"January","February","March","Apirl","May","June","july","August","september","October","November","December"};
int i,j,n,m,num0=0,num1=31,nweek0=week,nweek1;
if(year%4==0)
{
if(year%100!=0) month_day[2]=29;
else
{
if(year%400==0) month_day[2]=29;
else month_day[2]=28;
}
}
else month_day[2]=28;
system("CLS");
printf("The calendar of the year %d
",year);
for(m=0;m!=12;m+=2)
{
if(m-1
{
nweek0=week;
nweek1=(week+num1%7)>7?(week+num1%7)-7:(week+num1%7);
}
else
{
num0=num0+month_day[m-1]+month_day[m];
nweek0=(week+num0%7)>7?(week+num0%7)-7:(week+num0%7);
num1=num1+month_day[m]+month_day[m+1];
nweek1=(week+num1%7)>7?(week+num1%7)-7:(week+num1%7);
}
printf("%-10s %2d %-10s %2d
=========================== ===========================
Sun Mon Tue Wed thu Fri sat Sun Mon Tue Wed thu Fri sat
",month_name[m],m+1,month_name[m+1],m+2);
for(i=nweek0,j=nweek1,n=0;j!=nweek1-6*7;j--)
{
if(n
{
if(i>0) printf("%3d ",month_day[m]-i+1);
else if(i<=0)
{
if(i>-month_day[m+1]) printf("%3d ",-i+1);
else printf("%3d ",-i-month_day[m+1]+1);
}
i--;
j+=1;
n++;
}
else
{
if(j>0) printf("%3d ",month_day[m+1]-j+1);
else if(j<=0)
{
if(j>-month_day[m+2]) printf("%3d ",-j+1);
else printf("%3d ",-j-month_day[m+2]+1);
}
n++;
}
if(n==14)
{
printf("
");
n=0;
}
}
printf("=========================== ===========================
");
}
}
void startWeek(int year) //确定需要显示的年份的第一天是星期几
{
int start_week,days;
if(year>SIGN_YEAR)
{
days=(year-SIGN_YEAR)*365+(year-SIGN_YEAR)/4-(year-SIGN_YEAR)/100+(year-SIGN_YEAR)/400+(((year-SIGN_YEAR)%4)+3)/4+((year-SIGN_YEAR)%400==0?0:((year-SIGN_YEAR)%100==0?1:0));
start_week=(SIGN_WEEK+days%7)>7?(SIGN_WEEK+days%7)-7:(SIGN_WEEK+days%7);
}
else
{
days=(SIGN_YEAR-year)*365+(SIGN_YEAR-year)/4-(SIGN_YEAR-year)/100+(SIGN_YEAR-year)/400;
start_week=(SIGN_WEEK-days%7)>0?(SIGN_WEEK-days%7):(SIGN_WEEK-days%7+7);
}
calendar(start_week,year);
}
int main()
{
int year,i;
printf("1.Calendar
2.Query
Select:");
scanf("%d",&i);
if(i==1)
{
printf("Enter year:");
scanf("%d",&year);
startWeek(year);
}
else
{
//function 2 code
}
getchar();
getchar();
return 0;
}
解决方案四:
帮忙解决一下,谢谢了