哈尔滨工程大学ACM预热赛---E Mother's Day

链接:https://ac.nowcoder.com/acm/contest/554/E
来源:牛客网
 

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 32768K,其他语言65536K
64bit IO Format: %lld

题目描述

Mother's Day is a celebration honoring the mother of the family, as well as motherhood, maternal bonds, and the influence of mothers in society, which is celebrated on various days in many parts of the world, but mostly, the date is on the second Sunday in May. 
    Like Mother's Day, there are also several celebrations have no fixed date, but are set in the form of "the Bth(st/nd) weekday C of the Ath(st/nd) month in a year", for example, as above, Mother's Day is on the second Sunday in May of a year, but also can be described as "the 2nd weekday 7 of the 5st month in a year"(A=5, B=2, C=7). 
    Now, to help remember these special days, HVT wants you to calculate all the exact date of such celebrations in the past and future hundreds of years, which means that you are given 4 numbers: A(1 ≤ A ≤ 12), B(B ≥ 1), C(1 ≤ C ≤ 7, 1=Monday,2=Tuesday,...,7=Sunday) and y(represents the year, 1850 ≤ y ≤ 2050), and you should write code to calculate the exact date of "the Bth(st/nd) weekday C of the Ath(st/nd) month in a year y".
    For your convenience, we will noice you that: January 1st, 1850 is a Tuesday.

 

输入描述:

The input contains multiple lines of test data, each line has 4 numbers: A B C and y.

输出描述:

For each input, you should output a exact date in the format of "yyyy/mm/dd"(When the number of digits is insufficient, 0 should be added to the front);
if the Bth(st/nd) weekday C of the Ath(st/nd) month in a year y does not exist(for example, there will never be a 7th Monday in any months of any year), you should output "none" (without quotes).

示例1

输入

复制

4 2 7 2018
4 1 7 2018
2 5 4 2018
2 4 3 2018

输出

复制

2018/04/08
2018/04/01
none
2018/02/28

代码:

#include<set>
#include<map>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int month,week,weekday,year;
    int s[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};//月份的天数
    while(~scanf("%d %d %d %d",&month,&week,&weekday,&year))
    {
        int number=1;
        for(int i=1850; i<year; i++)//记录年份的天数,找到星期几
        {
            if(i%400==0||(i%4==0&&i%100!=0))
                number=(number+366)%7;
            else
                number=(number+365)%7;
        }
        for(int i=1; i<month; i++)//记录月份的天数,找到星期几
            number=(number+s[i])%7;
        if(year%400==0||(year%4==0&&year%100!=0))//是闰年,天数+1
            number++;
        int sum=0;//记录year年第month月的第week周的星期weekday是month月的第sum天
        number=number%7;
        while(1)//处理当前月month
        {
            sum++;
            number++;
            if(number==8)
                number=1;
            if(number==weekday)
                week--;
            if(week==0)
                break;
        }
        if(sum>s[month])
            printf("none\n");
        else
            printf("%02d/%02d/%02d\n",year,month,sum);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值