zoukankan      html  css  js  c++  java
  • 2017"百度之星"程序设计大赛

    Problem Description

    今天是2017年8月6日,农历闰六月十五。

    小度独自凭栏,望着一轮圆月,发出了“今夕何夕,见此良人”的寂寞感慨。

    为了排遣郁结,它决定思考一个数学问题:接下来最近的哪一年里的同一个日子,和今天的星期数一样?比如今天是8月6日,星期日。下一个也是星期日的8月6日发生在2023年。

    小贴士:在公历中,能被4整除但不能被100整除,或能被400整除的年份即为闰年。

    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
    

     解法:

    题目http://codeforces.com/contest/678/problem/B类似

    http://www.cnblogs.com/yinghualuowu/p/5587027.html

     1 #include<stdio.h>
     2 #include<string>
     3 #include<iostream>
     4 #include<math.h>
     5 #include<time.h>
     6 #include <stdlib.h>
     7 using namespace std;
     8 int Day_weak(int year,int month,int day)
     9 {
    10     if(month==1||month==2)
    11     {
    12         month +=12;
    13         --year;
    14     }
    15     int week = -1;
    16     week=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400)%7+1;
    17     return week; // 输出-1为错误
    18 }
    19 int cmd(int n){
    20     if((n%4==0&&n%100!=0)||(n%400==0)){
    21         return 1;
    22     }
    23     return 0;
    24 }
    25 int main()
    26 {
    27     int t;
    28     cin>>t;
    29     while(t--){
    30         int a,b,c;
    31         int i;
    32         scanf("%d-%d-%d",&a,&b,&c);
    33         for(i=a+1;;i++)
    34         {
    35            if(cmd(i)==0&&b==2&&c==29) continue;
    36            if(Day_weak(a,b,c)==Day_weak(i,b,c))
    37            {
    38                break;
    39            }
    40         }
    41         cout<<i<<endl;
    42     }
    43     return 0;
    44 }
  • 相关阅读:
    alpha版本发布前的进度
    1.26~1.27
    1.23~1.25
    1月21日~1月22日工作情况
    1月17日工作情况
    1月16日小组开会
    1月15日工作进度
    1月12日~1月14日工作进度
    linux下的动态链接库管理
    小组第一次小组讨论
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7350802.html
Copyright © 2011-2022 走看看