您现在的位置:首页 > >

已知1990年1月1号星期1.求出输入的年月日是星期几

发布时间:

参考地址:http://topic.csdn.net/u/20110822/17/ef33b75f-a67c-413d-9b33-9c8dfc34e2f9.html



#include
using namespace std;
void main()
{
//已知1990年1月1号星期1.求出输入的年月日是星期几
int year,month,day;//年月日
int num=0,leap,week;
int sum=0;
cout<<"请输入年月日"< cin>>year;
cin>>month;
cin>>day;
if(year>=1990)//当输入的年大于1990
{
for(int i=1990;i {
if((i%4==0&&i%100!=0)||(i%400==0))
num+=366;
else
num+=365;
}
if((year%4==0&&year%100!=0)||(year%400==0))
leap=1;
else
leap=0;
switch(month-1)//计算月的天数
{
case 11:
sum=num+365+leap-31;
break;
case 10:
sum=num+365+leap-31-30;
break;
case 9:
sum=num+365+leap-31-30-31;
break;
case 8:
sum=num+365+leap-31-30-31-30;
break;
case 7:
sum=num+365+leap-31-30-31-30-31;
break;
case 6:
sum=num+365+leap-31-30-31-30-31-31;
break;
case 5:
sum=num+365+leap-31-30-31-30-31-31-30;
break;
case 4:
sum=num+365+leap-31-30-31-30-31-31-30-31;
break;
case 3:
sum=num+365+leap-31-30-31-30-31-31-30-31-30;
break;
case 2:
sum=num+365+leap-31-30-31-30-31-31-30-31-30-31;
break;
case 1:
sum=num+365+leap-31-30-31-30-31-31-30-31-30-31-28-leap;
break;
case 0:
sum=num;
break;
default:
break;
}
sum=sum+day-1;//求天数总和
cout<<"总天数为"< week=sum%7;//求出天数
if(week!=0)
cout< else
cout<}
else//小于1990 同上
{
for(int i=year+1;i<1990;i++)
{
if((i%4==0&&i%100!=0)||(i%400==0))
num+=366;
else
num+=365;
}
if((year%4==0&&year%100!=0)||(year%400==0))
leap=1;
else
leap=0;
switch(month)
{
case 12:
sum=num;
break;
case 11:
sum=num+31;
break;
case 10:
sum=num+31+30;
break;
case 9:
sum=num+31+30+31;
break;
case 8:
sum=num+31+30+31+30;
break;
case 7:
sum=num+31+30+31+30+31;
break;
case 6:
sum=num+31+30+31+30+31+31;
break;
case 5:
sum=num+31+30+31+30+31+31+30;
break;
case 4:
sum=num+31+30+31+30+31+31+30+31;
break;
case 3:
sum=num+31+30+31+30+31+31+30+31+30;
break;
case 2:
sum=num+31+30+31+30+31+31+30+31+30+31;
break;
case 1:
sum=num+31+30+31+30+31+31+30+31+30+31+28+leap;
break;
default:
break;
}
if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
{
sum=sum+31-day+1;
}
if(month==4||month==6||month==9||month==11)
{
sum=sum+30-day+1;
}
if (month==2)
{
sum=sum+28+leap-day+1;
}
cout<<"总天数为"< week=sum%7;//求出天数
if(week!=0)
cout< else
cout<}
}








热文推荐
猜你喜欢
友情链接: