Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Why WA?#include <iostream.h> #include <string.h> int mon[2][13]= { {0,31,59,90,120,151,181,212,243,273,304,334,365}, {0,31,60,91,121,152,182,213,144,174,305,335,366} }; char * getWeekDay(int n) { int a = (n+6)%7; char *wd = new char[10]; switch(a) { case 0: strcpy(wd,"Sunday"); break; case 1: strcpy(wd,"Monday"); break; case 2: strcpy(wd,"Tuesday"); break; case 3: strcpy(wd,"Wednesday"); break; case 4: strcpy(wd,"Thursday"); break; case 5: strcpy(wd,"Friday"); break; case 6: strcpy(wd,"Saturday"); break; } return wd; } void getYear(int n,int &y,int &m,int &d) { int i,a,flag = 0; a = 2000+(int)(n-1)/365; if (a%4==0 && a%400==0) { flag = 1; } a = (int)(a - 2000)/4; y = 2000 + (int)(n-1-a)/365; a = (n-1-a)%365; for(i=1;i<=12;i++) { if(a<=mon[flag][i]) { m = i; d = a-mon[flag][i-1]+1; break; } } } void doRun() { int a; int y,m,d; while(cin>>a) { if(a == -1||a<=0)break; getYear(a,y,m,d); if(y>9999)break; cout<<y<<"-"<<(m>9?"":"0")<<m<<"-"<<(d>9?"":"0")<<d<<" "<<getWeekDay(a)<<endl; } } int main() { doRun(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator