日期小助手

日期小助手

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

题目描述
作为一个关心父母的孩子,Compute 会在每年的母亲节和父亲节为父母准备礼物。可是粗心的他却不记得它们的具体日期了。
已知:母亲节在每年 5 月的第 2 个周日;父亲节在每年 6 月的第 3 个周日。
现在你需要告诉他,下一个(不包括当天)母亲节或父亲节是在什么时候。
输入描述:
第一行包含一个整数 T (T \leq 100T≤100),表示测试数据的组数。
对于每组数据,包含三个整数 y, m, d,中间以空格分隔,分别表示今天的年、月、日。
输入保证是一个在公元 2000 年 1 月 1 日 到 2100 年 12 月 31 日间的合法日期。
输出描述:
对于每组数据,在一行输出下一个需要准备礼物的节日和日期。格式参考样例输出。
找规律把每一年的母亲节和父亲节找出来打表,但是一开始我把英语单词弄错了,就一直错。
示例1
输入

7
2000 1 1
2001 1 1
2002 1 1
2003 1 1
2020 1 1
2020 5 10
2020 6 21

输出

Mother’s Day: May 14th, 2000
Mother’s Day: May 13th, 2001
Mother’s Day: May 12th, 2002
Mother’s Day: May 11th, 2003
Mother’s Day: May 10th, 2020
Father’s Day: June 21st, 2020
Mother’s Day: May 9th, 2021

#include<bits/stdc++.h>
using namespace std;
map<int, int>mp1;
map<int, int>mp2;
 
void dabiao()
{
    mp1[2000] = 14;
    int num = (31-mp1[2000])%7;
    mp2[2000] = 21 - num;
    for(int i = 2001; i <= 2102; i++)
    {
        mp1[i] = mp1[i-1] -1;
        if(mp1[i]<=7) mp1[i]+=7;
        if((i%4==0&&i%100!=0)||(i%400==0))  mp1[i] -=1;
        if(mp1[i]<=7) mp1[i]+=7;
        num = (31-mp1[i])%7;
        mp2[i] = 21-num;
    }
}
 
 
int main()
{
    dabiao();
    int t;
    scanf("%d", &t);
    while(t--)
    {
        int y, m, d;
        scanf("%d %d %d", &y, &m, &d);
        if((m<=4&&m>=1)||(m==5&&d<mp1[y]))
        {
            if(mp1[y]==21) printf("Mother's Day: May %dst, %d\n", mp1[y], y);
            else if(mp1[y]==22) printf("Mother's Day: May %dnd, %d\n", mp1[y], y);
            else if(mp1[y]==23) printf("Mother's Day: May %drd, %d\n", mp1[y], y);
            else printf("Mother's Day: May %dth, %d\n", mp1[y], y);
            continue;
        }
        if((m==5&&d>=mp1[y])||(m==6&&d<mp2[y]))
        {
            if(mp2[y]==21) printf("Father's Day: June %dst, %d\n", mp2[y], y);
            else if(mp2[y]==22) printf("Father's Day: June %dnd, %d\n", mp2[y], y);
            else if(mp2[y]==3) printf("Father's Day: June %drd, %d\n", mp2[y], y);
            else printf("Father's Day: June %dth, %d\n", mp2[y], y);
            continue;
        }
        if((m>=7&&m<=12)||(m==6&&d>=mp2[y]))
        {
            y++;
            if(mp1[y]==21) printf("Mother's Day: May %dst, %d\n", mp1[y], y);
            else if(mp1[y]==22) printf("Mother's Day: May %dnd, %d\n", mp1[y], y);
            else if(mp1[y]==23) printf("Mother's Day: May %drd, %d\n", mp1[y], y);
            else printf("Mother's Day: May %dth, %d\n", mp1[y], y);
            continue;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值