HuaWeiExam

#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;

bool isrun(int a) {
    if ((a % 4 == 0 && a % 100 != 0) || a % 400 == 0)
        return true;
    else
        return false;
}

bool isbig(int a) {
    int b[] = { 1,3,5,7,8,10,12 };
    for (int i = 0; i < 7; i++)
    {
        if (a == b[i])
            return true;
    }
    return false;
}

using namespace std;

int main() {
    int Year;
    int Mo;
    int weeks;
    int days;
    int weekdays;
    int outdays;
    int sumdays;
    cin >> Year;
    cin >> Mo;
    cin >> weeks;
    cin >> days;
    weekdays = ((Year - 2000) / 4 + (Year - 2000) * 365 + 6) % 7;
    int weekday[12];
    weekday[0] = (weekdays + 31) % 7;
    weekdays = weekday[0];
    if (isrun(Year))
    {
        weekday[1] = (weekdays + 29) % 7;
        weekdays = weekday[1];
    }
    else {
        weekday[1] = (weekdays + 28) % 7;
        weekdays = weekday[1];
    }
    for (int i = 2; i < 12; i++)
    {
        if (isbig(i + 1)) {
            weekday[i] = (weekdays + 31) % 7;
                weekdays = weekday[i];
        }
        else {
            weekday[i] = (weekdays + 30) % 7;
                weekdays = weekday[i];
        }
    }
    if (isrun(Year))
    {
        if (Mo == 2)
        {

            if ((weeks * 7 + days) > 29)
            {
                cout << "0" << endl;
                return 0;
            }
            else if (days > 7)
            {
                cout << "0" << endl;
                return 0;
            }
            else {
                outdays = weeks * 7 + days;
                sumdays = outdays + 31;
                outdays = outdays - weekday[1];
            }
        }
        else if (isbig(Mo))
        {
            if ((weeks * 7 + days) > 31)
            {
                cout << "0" << endl;
                return 0;
            }
            else if (days > 7)
            {
                cout << "0" << endl;
                return 0;
            }
            else {
                outdays = weeks * 7 + days;
                outdays = outdays - weekday[Mo - 1];
            }
        }
        else {
            if ((weeks * 7 + days) > 30)
            {
                cout << "0" << endl;
                return 0;
            }
            else if (days > 7)
            {
                cout << "0" << endl;
                return 0;
            }
            else {
                outdays = weeks * 7 + days;
                outdays = outdays - weekday[Mo - 1];
            }

        }
    }
    else {
        if (Mo == 2)
        {

            if ((weeks * 7 + days) > 28)
            {
                cout << "0" << endl;
                return 0;
            }
            else if (days > 7)
            {
                cout << "0" << endl;
                return 0;
            }
            else {
                outdays = weeks * 7 + days;
                sumdays = outdays + 31;
                outdays = outdays - weekday[1];
            }
        }
        else if (isbig(Mo))
        {
            if ((weeks * 7 + days) > 31)
            {
                cout << "0" << endl;
                return 0;
            }
            else if (days > 7)
            {
                cout << "0" << endl;
                return 0;
            }
            else {
                outdays = weeks * 7 + days;
                outdays = outdays - weekday[Mo - 1];
            }
        }
        else {
            if ((weeks * 7 + days) > 30)
            {
                cout << "0" << endl;
                return 0;
            }
            else if (days > 7)
            {
                cout << "0" << endl;
                return 0;
            }
            else {
                outdays = weeks * 7 + days;
                outdays = outdays - weekday[Mo - 1];
            }

        }
    }
    if (Mo > 9)
    {
        if (outdays > 9)
            cout << Year << "-" << Mo << "-" << outdays << endl;
        else
            cout << Year << "-" << Mo << "-0" << outdays << endl;
    }
    else {
        if (outdays > 9)
            cout << Year << "-0" << Mo << "-" << outdays << endl;
        else
            cout << Year << "-0" << Mo << "-0" << outdays << endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值