hdu 6112 今夕何夕(模拟)

今夕何夕

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 484    Accepted Submission(s): 151

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
Source
傻逼题 开始一直算
直接模拟就可以了  不小心把c=1写成c==1
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<string.h>
 7 #include<set>
 8 #include<vector>
 9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<cmath>
13 typedef long long ll;
14 typedef unsigned long long LL;
15 using namespace std;
16 const double PI=acos(-1.0);
17 const double eps=0.0000000001;
18 const int INF=1e9;
19 const int N=1000+100;
20 int check(int x){
21     if(x%4==0&&x%100!=0)return 1;
22     if(x%400==0)return 1;
23     return 0;
24 }
25 int fun(int x){
26     if(x==1||x==3||x==5||x==7)return 1;
27     if(x==8||x==10||x==12)return 1;
28     return 0;
29 }
30 int main(){
31     int t;
32     scanf("%d",&t);
33     while(t--){
34         int y,m,d;
35         scanf("%d-%d-%d",&y,&m,&d);
36         int a=y,b=m,c=d;
37         for(int i=1;i<=10000000;i++){
38             c=c+1;
39             if(check(a)&&b==2&&c==30){
40                 b++;
41                 c=1;
42             }
43             else if(check(a)==0&&b==2&&c==29){
44                 b++;
45                 c=1;
46             }
47             else if(fun(b)==1&&c==32){
48                 b++;
49                 c=1;
50             }
51             else if(fun(b)==0&&c==31){
52                 b++;
53                 c=1;
54             }
55             if(b==13){
56                 a++;
57                 b=1;
58             }
59             //cout<<a<<" "<<b<<" "<<c<<endl;
60             if(b==m&&c==d&&i%7==0){
61                 cout<<a<<endl;
62                 break;
63             }
64         }
65     }
66 }

 

posted on 2017-08-12 19:19  见字如面  阅读(253)  评论(0编辑  收藏  举报

导航