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;
    }
    
    
  • 相关阅读:
    年底送书活动:送出6本技术书籍,价值372元!
    (7)ASP.NET WEB服务器控件
    (6)DataTable 转换成 Json
    (9)C#连mysql
    (8)C#连sqlserver
    VM虚拟机
    (7)C#连DB2---oledb方式
    (48)C#网络4 web
    远程桌面
    (47)C#运行时序列化
  • 原文地址:https://www.cnblogs.com/lengxia/p/4387836.html
Copyright © 2011-2022 走看看