我是靠谱客的博主 失眠啤酒,最近开发中收集的这篇文章主要介绍哈尔滨工程大学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("nonen");
        else
            printf("%02d/%02d/%02dn",year,month,sum);
    }
    return 0;
}

最后

以上就是失眠啤酒为你收集整理的哈尔滨工程大学ACM预热赛---E Mother's Day代码:的全部内容,希望文章能够帮你解决哈尔滨工程大学ACM预热赛---E Mother's Day代码:所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(51)

评论列表共有 0 条评论

立即
投稿
返回
顶部