cpp 1124 显示星期几

题目链接:?ShowID=1124

题面:

显示星期几Time Limit:1000MS Memory Limit:32768K

Description:针对输入的日期,,输出对应的星期几。一个星期的每天对应字串"Mon.","Tus.","Wed.",""Thr.","Fri.","Sat.","Sun."。Input:第一个整数N表示后面有N个日期。其日期结构为“YYYY-MM-DD”。Output:根据每个日期输出英文压缩星期几的名字。Sample Input:32006-04-222006-04-282006-03-01Sample Output: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;}}

梦想让我与众不同,奋斗让我改变命运!

cpp 1124 显示星期几

相关文章:

你感兴趣的文章:

标签云: