用蔡勒公式求星期几,得不到想要的结果,紧急
#include <cstdlib>#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int y,m,d;
while(cin>>y>>m>>d){
if(y==0&&m==0&&d==0) break;
if(y%400==0||(y%4==0&&y%100!=0))
{ if(m==2&&(d<1||d>29)) {cout<<-1<<endl;continue;}
if((m==4||m==6||m==9||m==11)&&(d<1||d>30)) {cout<<-1<<endl;continue;}
if((m==1||m==3||m==5||m==7)&&(d<1||d>31)) {cout<<-1<<endl;continue;}
if((m==8||m==10||m==12)&&(d<1&&d>31)) {cout<<-1<<endl;continue;}}
else { if(m==2&&(d<1||d>28)) {cout<<-1<<endl;continue;}
if((m==4||m==6||m==9||m==11)&&(d<1||d>30)) {cout<<-1<<endl;continue;}
if((m==1||m==3||m==5||m==7)&&(d<1||d>31)) {cout<<-1<<endl;continue;}
if((m==8||m==10||m==12)&&(d<1&&d>31)) {cout<<-1<<endl;continue;}}
if(m<3){ m=m+12;
y=y-1;}
y=y%100;
int w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
switch(w+1){
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;}}
return EXIT_SUCCESS;
}
目测蔡勒公式没用错啊,可就是得不到正确结果,请指点迷津