2017百度之星资初赛(A)--E:今夕何夕

Input

第一行为T,表示输入数据组数。

每组数据包含一个日期,格式为YYYY-MM-DD。

1 ≤ T ≤ 10000

YYYY ≥ 2017

日期一定是个合法的日期

Output

对每组数据输出答案年份,题目保证答案不会超过四位数。

Sample Input
3
2017-08-06
2017-08-07
2018-01-01
Sample Output
2023
2023
2024
由于考虑到最多400年一次轮回,所以可以考虑暴力,对于输入大于2月29的情况,我们只要考虑下一年是否是闰年就行,小于2月29的情况,我们要考虑当前年是否是闰年,对于是闰年又是2月29号的情况,我们要每次都判断,并且,要在闰年的时候是否是满足的情况。每次年份只能加1.要考虑到每一百年的 情况。

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string.h>
#define LL __int64
#define siz 1005
#define LL long long
using namespace std;
int n,m,k;
int year,month,day;
void solve(){
    if((((year)%4==0&&(year)%100!=0)||(year)%400==0)&&month==2&&day==29){
            int t=0;
            LL ans = 0;

            while(true){
                //++t;
                ++year;
                if(((year)%4==0&&(year)%100!=0)||(year)%400==0){
                    ans += 366;
                    if(ans%7==0){
                    printf("%d\n",year);
                    break;
                }
                }
                else{
                    ans += 365;
                }
                //ans+=1461;
               // t+=4;

            }
           return ;
        }
    LL ans = 0;
   for(int i=1;i<=10000;i++){
        int ye;
        if(month>2){
            ye = year +i;
        }
        else{
            ye = year+i-1;
        }
        //int ye = year + i;
        if(((ye)%4==0&&(ye)%100!=0)||(ye)%400==0){
            ans += 366;
        }
        else{
            ans += 365;
        }
        if(ans%7==0){
            if(month>=32)
            printf("%d\n",ye);
            else{
                printf("%d\n",ye+1);
            }
            break;
        }
   }
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--){
       // int p;
        scanf("%d-%d-%d",&year,&month,&day);
        
       solve();
    }
    return 0;
}





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值