zoukankan      html  css  js  c++  java
  • Calendar

    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

    1730
    1740
    1750
    1751
    -1

    Sample Output

    2004-09-26 Sunday
    2004-10-06 Wednesday
    2004-10-16 Saturday
    2004-10-17 Sunday
    
    #include <iostream>
    #include<string>
    using namespace std;
    int main()
    {int t,i;
    string xing;
    while(cin>>t,t>=0)
    {i=t%7;
    t++;
    int nian=2000,yun[13],yue;
    switch(i)
    {case 1:xing="Sunday";break;
    case 2:xing="Monday";break;
    case 3:xing="Tuesday";break;
    case 4:xing="Wednesday";break;
    case 5:xing="Thursday";break;
    case 6:xing="Friday";break;
    case 0:xing="Saturday";break;
    default:break;
    }
    while(t>=366)
    {if(nian%4==0&&nian%100!=0||nian%400==0) 
    {if(t==366)break;
    else t-=366;nian++;}
    else
    {t-=365;nian++;}
    }
    yun[1]=yun[5]=yun[3]=yun[7]=yun[8]=yun[10]=yun[12]=31;
    yun[4]=yun[6]=yun[9]=yun[11]=30;
    if(nian%4==0&&nian%100!=0||nian%400==0) 
    yun[2]=29;
    else yun[2]=28;
    for(i=1;i<=12;i++)
    {    if(t<=yun[i])break;
        else t=t-yun[i];
    }
    yue=i;
    if(yue<10&&t>=10)
    cout<<nian<<"-0"<<yue<<"-"<<t;
    if(yue<10&&t<10)
    cout<<nian<<"-0"<<yue<<"-0"<<t;
    if(yue>=10&&t<10)
    cout<<nian<<"-"<<yue<<"-0"<<t;
    if(yue>=10&&t>=10)
    cout<<nian<<"-"<<yue<<"-"<<t;
    
    cout<<" "<<xing<<endl;
    }
    return 0;
    }
    
    
  • 相关阅读:
    【云速建站】购买前的指导
    【云速建站】域名配置指导
    Python爬虫批量下载糗事百科段子,怀念的天王盖地虎,小鸡炖蘑菇...
    舌尖上的安全
    【云速建站】视频播放专题
    Python装饰器总结,带你几步跨越此坑!
    让你提前认识软件开发(15):程序调试的利器—日志
    Win8下IIS的安装和站点的公布
    [2011山东ACM省赛] Mathman Bank(模拟题)
    Android UI开发神兵利器之Android Action Bar Style Generator
  • 原文地址:https://www.cnblogs.com/lengxia/p/4387836.html
Copyright © 2011-2022 走看看