Poj2080:calendar (calculated date)

Source: Internet
Author: User

Calendar
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 12842 Accepted: 4641

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 is all units of time measurements of a calender system.
According to the Gregorian calendar, which was the civil calendar in use today, years evenly divisible by 4 are leap years, With the exception of centurial years is not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100 is not a leap years, but a, a, and 2400 is leap years.
Given the number of days that has elapsed since January 1, a-A.D, your mission is-find the date and the day of the Week.

Input

The input consists of lines each containing a positive integer, which are the number of days that has elapsed since Januar Y 1, A.D. The last line contains a integer−1, which should not being processed.
Assume that the resulting date won ' t is 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", W Here "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

Note: Select day of the Week is Sunday as the base date.
#include <iostream>using namespacestd;intmds[ -]={0, to, -, to, -, to, -, to, to, -, to, -, to};Charweek[8][ -]={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};BOOLIsleap (intYear ) {    if((year%4==0&&year% -!=0)|| year% -==0)    {        return true; }    return false;}intMain () {intstandard=0;  for(intI= -; i<= -; i++)        {        if(Isleap (i)) standard+=366; Elsestandard+=365; }     for(intI=1; i<=6; i++) { standard+=Mds[i]; }    if(Isleap ( .)) standard++; Standard+=3;//2016-07-03 is Sunday.    intdiff; intDays ;  while(cin>>days&&days!=-1) {diff=days-Standard ; Diff++; intYear= -; intD=1; intm=1;  while(true)        {            if(Isleap (year)) {if(days>=366) { days-=366; year++; }                Else     Break; }                Else            {                if(days>=365) { days-=365; year++; }                Else     Break; }        }         while(true)        {            intms=Mds[m]; if(Isleap (year) &&m==2) {MS++; }            if(days>=ms) { days-=MS; M++; }            Else     Break; } d+=Days ; cout<<year<<"-"; if(m<Ten) cout<<"0"; cout<<m<<"-"; if(d<Ten) cout<<"0"; cout<<d<<" "; if(diff>=0) {diff%=7; cout<<Week[diff]<<Endl; }        Else{diff=-diff; Diff%=7; if(diff==0) diff=7; cout<<week[7-diff]<<Endl; }    }    return 0;}

Poj2080:calendar (calculated date)

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.