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 |
ACCEPT!!!#include<iostream> #include<iomanip> using namespace std; bool isleap(int num) { if(num%400==0) return true; if(num%100==0) return false; if(num%4==0) return true; return false; } void date(int num) { int year=2000; int month=1; int day=1; int weekday=6; while(num) { while(1) if(num>365&&isleap(year)==false) { year+=1; num-=365; weekday+=1; if(weekday>7) weekday-=7; } else if(num>366&&isleap(year)==true) { year+=1; num-=366; weekday+=2; if(weekday>7) weekday-=7; } else break; weekday++; if(weekday==8) weekday-=7; day+=1; if(month==2) { if(isleap(year)==false&&day==29) { day-=28; month+=1; } else if(isleap(year)==true&&day==30) { day-=29; month+=1; } } else if(month==4||month==6||month==9||month==11) { if(day==31) { day-=30; month+=1; } } else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) { if(day==32) { day-=31; month+=1; } } if(month==13) { month-=12; year+=1; } num--; } cout<<setw(4)<<setfill('0')<<year; cout<<"-"; cout<<setw(2)<<setfill('0')<<month; cout<<"-"; cout<<setw(2)<<setfill('0')<<day; cout<<" "; if(weekday==1)cout<<"Monday"<<endl; if(weekday==2)cout<<"Tuesday"<<endl; if(weekday==3)cout<<"Wednesday"<<endl; if(weekday==4)cout<<"Thursday"<<endl; if(weekday==5)cout<<"Friday"<<endl; if(weekday==6)cout<<"Saturday"<<endl; if(weekday==7)cout<<"Sunday"<<endl; } int main() { int num; cin>>num; while(num!=-1) { date(num); cin>>num; } return(0); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator