求高手解答C++计算星期几
#include <cstdlib>#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
while(1){
int y,m,d;
int mon[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int n,N;
cin>>y>>m>>d;
if(y==0&&m==0&&d==0) break;
if(y%400==0||(y%4==0&&y%100!=0))
{ mon[1]=29;
if(y<2000||y>9999||m>12||m<1||d<1||d>29)
cout<<-1<<endl;
else {n=(y-1)/4-((y-1)/100-(y-1)/400);
N=365*(y-1)+n;
for(int i=0;i<m-1;i++)
N+=mon[i];
N+=d;
switch(N%7)
{
case 0:cout<<7<<endl;break;
case 1:cout<<1<<endl;break;
case 2:cout<<2<<endl;break;
case 3:cout<<3<<endl;break;
case 4:cout<<4<<endl;break;
case 5:cout<<5<<endl;break;
case 6:cout<<6<<endl;break;
}}}
else{
if(y<2000||y>9999||m>12||m<1||d<1||d>28)
cout<<-1<<endl;
else{
n=(y-1)/4-((y-1)/100-(y-1)/400);
N=365*(y-1)+n;
for(int i=0;i<m-1;i++)
N+=mon[i];
N+=d;
switch(N%7)
{
case 0:cout<<7<<endl;break;
case 1:cout<<1<<endl;break;
case 2:cout<<2<<endl;break;
case 3:cout<<3<<endl;break;
case 4:cout<<4<<endl;break;
case 5:cout<<5<<endl;break;
case 6:cout<<6<<endl;break;
}}}}
system("PAUSE");
return EXIT_SUCCESS;
}
输入 年 月 日(2000<=年<=9999)求出星期几用1-7表示,输入不合理时输出-1,输入0 0 0时结束