## Calendar

Time Limit: 1 Seconds Memory Limit: 32768 KB

A calendar is a system for measuring time, from hours and minutes, to months and days, and finally to years and centuries. The terms of hour, day, month, year and century are all units of time measurements of a calender system.

According to the Gregorian calendar, which is the civil calendar in use today, years evenly divisible by 4 are leap years, with the exception of centurial years that are not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100 are not leap years, but 1600, 2000, and 2400 are leap years.

Given the number of days that have elapsed since January 1, 2000 A.D, your mission is to find the date and the day of the week.

Input

The input consists of lines each containing a positive integer, which is the number of days that have elapsed since January 1, 2000 A.D. The last line contains an integer -1, which should not be processed. You may assume that the resulting date won't be after the year 9999.

Output

For each test case, output one line containing the date and the day of the week in the format of "YYYY-MM-DD DayOfWeek", where "DayOfWeek" must be one of "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" and "Saturday".

Sample Input

```1730 1740 1750 1751 -1```

Output for Sample Input

```2004-09-26 Sunday 2004-10-06 Wednesday 2004-10-16 Saturday 2004-10-17 Sunday```

Source:Asia 2004, Shanghai (Mainland China), Preliminary

CODE

```#include<stdio.h> #include<string.h> #include<stdbool.h>   struct { short year; short month; short day; short week; }list[3000000];   _Bool leap(int year) { return ((year%4==0&&year%100!=0)||year%400==0); }   int main() { int i,j,k,t; int cnt=0; int week=6; for(i=2000;i<=9999;++i) { for(j=1;j<=12;++j) { if(j==1||j==3||j==5||j==7||j==8||j==10||j==12) t=31; else if(j==2) if(leap(i)) t=29; else t=28; else t=30; for(k=1;k<=t;++k) { list[cnt].year=i; list[cnt].month=j; list[cnt].day=k; list[cnt].week=week; ++cnt; ++week; if(week==8)week=1; } } } int day; while(scanf("%d",&day),day!=-1) { printf("%d-",list[day].year); if(list[day].month<10)putchar('0'); printf("%d-",list[day].month); if(list[day].day<10)putchar('0'); printf("%d ",list[day].day); switch(list[day].week) { case 1:puts("Monday"); break; case 2:puts("Tuesday"); break; case 3:puts("Wednesday"); break; case 4:puts("Thursday"); break; case 5:puts("Friday"); break; case 6:puts("Saturday"); break; case 7:puts("Sunday"); break; } } return 0; }```
» 本博客采用署名 2.5 中国大陆许可协议进行许可，本文版权归作者所有，欢迎转载，但必须在明显位置给出原文连接。
anyShare分享到：