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;
    }
    
    
  • 相关阅读:
    网易举办首届云创大会,优云软件助力司南战略
    优云软件助阵ArchSummit全球架构师峰会
    优云软件闪耀中国双态运维大会·乌镇峰会
    优云亮相GOPS2017全球运维大会 “黑科技”获全场最高关注
    用Monitor简单3步监控中间件ActiveMQ
    优云软件应邀出席 ITSS 数据中心运营管理工作组 2017 年春季研讨会
    机器人运维时代已来临?这是真的......
    automation轻松“一点”,搞定裸机安装系统
    SEL Event Records
    工作摘要
  • 原文地址:https://www.cnblogs.com/lengxia/p/4387836.html
Copyright © 2011-2022 走看看