标签:des style blog http color strong
Description
Input
Output
Sample Input
1730 1740 1750 1751 -1
Sample Output
2004-09-26 Sunday 2004-10-06 Wednesday 2004-10-16 Saturday 2004-10-17 Sunday
//不知为何wa了,泪奔。。。。。 #include<iostream> #include <algorithm> #include<iomanip> using namespace std; int rn(int n) { int l=0; if(n%4==0&&n%100!=0||n%400==0) l=1; return l; } char week[7][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"}; int month[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31}; int main() { int n,i,j,s,m,d,m1; while(cin>>n&&n!=-1) { d=(n)%7; j=0; n++; s=2000; m1=1; if(n==366) j++; while(n>365+j) { n=n-365-rn(s); s++; j=0; } if(n>59) n=n-rn(s); while(n>0) { n-=month[0][m1]; m1++; } m1--; n+=month[0][m1]; cout<<s<<'-'; cout<<setw(2)<<setfill('0')<<m1<<'-'<<setw(2)<<setfill('0')<<n<<' '; cout<<week[d]<<endl;; } return 0; }//AC #include<stdio.h> int main(){ char w[7][10]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" ,"Saturday"}; int m[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31, 0,31,29,31,30,31,30,31,31,30,31,30,31}; int yd[2]={365,366}; long day; int year,month,week; int i,j,flag; while(scanf("%ld",&day)&&-1!=day){ week=(day+6)%7;//得到星期几 year=2000; flag=(0==year%4&&year%100!=0)||0==year%400;//flag=1为闰年 ++day;//题目说经过多少天,所以在这里先加1 for(;day>yd[flag];){//得到年份、剩余天数 day-=yd[flag]; year++; flag=(0==year%4&&year%100!=0)||0==year%400; } for(month=1;day>m[flag][month];++month){//得到月份和对应天数 day-=m[flag][month]; } printf("%d-%02d-%02d %s\n",year,month,day,w[week]);//%02d很方便 } }
标签:des style blog http color strong
原文地址:http://blog.csdn.net/rememberautumn/article/details/37811469