POJ

来源:互联网 发布:剑灵女咒术师捏脸数据 编辑:程序博客网 时间:2024/06/14 15:35
Calendar
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 13967 Accepted: 4951

Description

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

1730174017501751-1

Sample Output

2004-09-26 Sunday2004-10-06 Wednesday2004-10-16 Saturday2004-10-17 Sunday

Source

Shanghai 2004 Preliminary

题意:求在2000-1-1 n天后的日期


2000-1-1是星期六


#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){    char s[10][20]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};    int mm[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31};    int day,y,m;    while(cin>>day)    {        y = 2000,m = 1;        if(day==-1)            break;        day++;//要求的是2000-1-1 day天,就是不包含第一天,所以要 +1        int xq = (5 + day % 7) % 7;//星期是七天一周期,比较好求        while(day>=366)//判断剩余的天数是否大于今年的总天数,若小于则开始求月份        {            if(day-365==0)                break;            if((y%4==0&&y%100!=0)||y%400==0)            {                if(day-366==0)                    break;                day--;            }            day -= 365;            y++;        }        if((y%4==0&&y%100!=0)||y%400==0)//闰年二月份29天            mm[2]++;        for(;m<=12;m++)        {            if(day-mm[m]<=0)//若剩余天数比该月总天数小或相等,则其月份就确定了                break;            day-=mm[m];        }        printf("%d-%02d-%02d %s\n",y,m,day,s[xq]);        mm[2] = 28;    }    return 0;}