poj2080 Calendar

来源:互联网 发布:软件定制开发公司 编辑:程序博客网 时间:2024/06/05 22:52

B - Calendar
Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:30000KB     64bit IO Format:%I64d & %I64u
SubmitStatus Practice POJ 2080
Appoint description:

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

从这道题也发现了自己的错误  经常犯的一个错误 就是总是想着节省空间  结果不是超时  就是忽略为何节省空间。。

以后不能这样了。

#include <stdio.h>int day[9000];int main(){for(int i=2000;i<=9999+10;i++){if((i%4==0&&i%100)||i%400==0)day[i-2000]=366;elseday[i-2000]=365;}int n;int mon[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};char week[7][15]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};while(~scanf("%d",&n)&&n!=-1){if(n==0){printf("2000-01-01 Saturday\n");continue;}n++;int sum=0,Year=0,Month=0,Day=0;int all=n;for(int i=0;;i++){sum+=day[i];if(sum>=n){Year=i;sum-=day[i];break;}} Year=Year+2000;n=n-sum;if(day[Year-2000]==366) mon[2]=29;else mon[2]=28;sum=0;for(int i=1;i<13;i++){sum+=mon[i];if(sum>=n){Month=i;sum-=mon[i];break;}}Day=n-sum;printf("%d-",Year);if(Month<10)printf("0%d-",Month);elseprintf("%d-",Month);if(Day<10)printf("0%d",Day);elseprintf("%d",Day);printf(" %s\n",week[(all+5)%7]);}return 0;}


0 0
原创粉丝点击