codeup 1929: Day of Week时间处理

1929: Day of Week

时间限制: 1 Sec   内存限制: 32 MB
献花: 339   解决: 104
[ 献花][ 花圈][ TK题库]

题目描述

We now use the Gregorian style of dating in Russia. The leap years are years with number divisible by 4 but not divisible by 100, or divisible by 400.
For example, years 2004, 2180 and 2400 are leap. Years 2004, 2181 and 2300 are not leap.
Your task is to write a program which will compute the day of week corresponding to a given date in the nearest past or in the future using today’s agreement about dating.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
#define inf 0x3f3f3f
int month[13][2]= {{0,0},{31,31},{28,29},{31,31},{30,30},{31,31},{30,30},{31,31},{31,31},{30,30},{31,31},{30,30},{31,31}};
//month数组用来表示平年和闰年的每个月的天数,第一维表示月份,第二维0表示平年,1表示闰年
string monthname[13]={
    "",
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"  };
string weekday[7]={
    "Sunday",
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday"};
string ouweekday[7] = {
    "Monday",
    "Tuesday",
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday"
    };
bool judge(int y)//判断平闰年
{
    return (y%4==0&&y%100!=0)||(y%400==0);
}
int main()
{
    int a,b;
    string s;
    int m;
    while(cin>>a>>s>>b)
    {
        for(int i=1;i<=12;i++)
        {
            if(s==monthname[i])
                {
                    m=i;
                    break;
                }
        }
        int d=a+m*100+b*10000;
        int date1=d<20180422?d:20180422;
        int date2=d>20180422?d:20180422;
        int y1=date1/10000,m1=date1%10000/100,d1=date1%100;
        int y2=date2/10000,m2=date2%10000/100,d2=date2%100;
        int ans=0;
        while(y1<y2||m1<m2||d1<d2)//两个日期不相等就进行加一运算
        {
            d1++;
            if(d1>month[m1][judge(y1)])//如果小日期的天数大于该月的天数,进入下一个月,月份加一,置为下月1号
            {
                m1++;
                d1=1;
            }
            if(m1==13)//如果月份大于12,则进入下一年,月份置一
            {
                y1++;
                m1=1;
            }
            ans++;//累计天数
        }
        //cout<<ans<<endl;
        int cha=ans%7;
        if(d>20180422)//当题目所给时间比自己选定标准时间大时
        {
            cout<<weekday[cha]<<endl;
        }
        else//题目所给时间比自己选定时间小
        {
            if(cha==0)
            cout<<"Sunday"<<endl;
           else
        cout<<ouweekday[6-cha]<<endl;
        }

    }

    return 0;
}



输入

There is one single line contains the day number d, month name M and year number y(1000≤y≤3000). The month name is the corresponding English name starting from the capital letter.

输出

Output a single line with the English name of the day of week corresponding to the date, starting from the capital letter. All other letters must be in lower case.

样例输入

21 December 2012
5 January 2013

样例输出

Friday
Saturday
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值