题目链接:http://cpp.zjut.edu.cn/ShowProblem.aspx?ShowID=1124
题面:
显示星期几
Time Limit:1000MS Memory Limit:32768K
3 2006-04-22 2006-04-28 2006-03-01
Sat. Fri. Wed.
题意:就不赘述了。
代码:
#include <iostream> #include<cmath> using namespace std; int main() { int n; cin>>n; string s; while(n--) { cin>>s; int year=(s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0'); int month=(s[5]-'0')*10+(s[6]-'0'); int d=(s[8]-'0')*10+(s[9]-'0'); int x=(s[2]-'0')*10+(s[3]-'0'); int y=(x/4+x)%7; int m; if(month!=2&&month!=1) { if(month==5)m=0; else if(month==8)m=1; else if(month==3||month==11)m=2; else if(month==6)m=3; else if(month==9||month==12)m=4; else if(month==4||month==7)m=5; else m=6; } else { if((year%4==0&&year%100!=0)||year%400==0) { if(month==1)m=5; else m=1; } else { if(month==2)m=2; else m=6; } } int c=(d+m+y)%7; if(c==0)cout<<"Sun."<<endl; else if(c==1)cout<<"Mon."<<endl; else if(c==2)cout<<"Tus."<<endl; else if(c==3)cout<<"Wed."<<endl; else if(c==4)cout<<"Thr."<<endl; else if(c==5)cout<<"Fri."<<endl; else if(c==6)cout<<"Sat."<<endl; } }
原文地址:http://blog.csdn.net/david_jett/article/details/45151817