Poj 2080 calendar

Source: Internet
Author: User

/*

Chinese Question calendar
To give a number, ask you to ask for the date and week after 2000-1-1
Solution: the day of the week is a good solution. If you want to evaluate the 7 model, you will get the day of the week. He also told you that July 6 is Saturday.

Difficulties: Pay attention to the first character array of the day of the week. For the year, month, and day, the total number of days minus the number of days per day, and the number of years minus the total number of years,

Similarly, the month is the same, but the last one must be added;
Key Point: carefulness
Problem solving person: lingnichong
Solution time:
Problem solving experience: Pay attention to details
*/


Calendar
Time limit:1000 ms   Memory limit:30000 K
Total submissions:11335   Accepted:4189

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,180 0, 1900 and 2100 are not leap years, But 1600,200 0, 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 shocould 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 containg 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




#include<stdio.h>int m1[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,31,29,31,30,31,30,31,31,30,31,30,31};int year[2]={365,366};char week[7][10]={"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};int leap(int m){if(m%4==0&&m%100!=0||m%400==0)return 1;elsereturn 0;}int main(){int day,weekday;int i,j;while(scanf("%d",&day),day!=-1){weekday=day%7;for(i=2000;day>=year[leap(i)];i++)day-=year[leap(i)];for(j=0;day>=m1[leap(i)][j];j++)day-=m1[leap(i)][j];printf("%d-%02d-%02d %s\n",i,j+1,day+1,week[weekday]);}return 0;}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.