标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 12842 | Accepted: 4641 |
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
注意:选取 Day of Week is Sunday 的日期作为基准日期.
#include <iostream> using namespace std; int mds[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char Week[8][20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}; bool isLeap(int year) { if((year%4==0&&year%100!=0)||year%400==0) { return true; } return false; } int main() { int standard=0; for(int i=2000;i<=2015;i++) { if(isLeap(i)) standard+=366; else standard+=365; } for(int i=1;i<=6;i++) { standard+=mds[i]; } if(isLeap(2016)) standard++; standard+=3;//2016-07-03 is Sunday. int diff; int days; while(cin>>days&&days!=-1) { diff=days-standard; diff++; int year=2000; int d=1; int m=1; while(true) { if(isLeap(year)) { if(days>=366) { days-=366; year++; } else break; } else { if(days>=365) { days-=365; year++; } else break; } } while(true) { int ms=mds[m]; if(isLeap(year)&&m==2) { ms++; } if(days>=ms) { days-=ms; m++; } else break; } d+=days; cout<<year<<"-"; if(m<10) cout<<"0"; cout<<m<<"-"; if(d<10) cout<<"0"; cout<<d<<" "; if(diff>=0) { diff%=7; cout<<Week[diff]<<endl; } else { diff=-diff; diff%=7; if(diff==0) diff=7; cout<<Week[7-diff]<<endl; } } return 0; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5641854.html