题意:中文题
思路:每次加一年的天数,然后判模7是不是等于0,如果等于0就说明这年可行,要判时间是否合法,比如找到了2019-2-29就是不合法的,然后在2-29前的和2-29及其以后的有一点不一样,看代码把
AC代码:
#include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm" #include "stdio.h" #include "math.h" #pragma comment(linker, "/STACK:102400000,102400000") #define ll long long #define endl ("\n") #define bug(x) cout<<x<<" "<<"UUUUU"<<endl; #define mem(a,x) memset(a,x,sizeof(a)) #define mp(x,y) make_pair(x,y) #define pb(x) push_back(x) #define ft first #define sd second #define lrt (rt<<1) #define rrt (rt<<1|1) using namespace std; const long long INF = 1e18+1LL; const int inf = 1e9+1e8; const int N=1e5+100; const ll mod=1e9+7; int is[N]; void init(){ for(int i=1; i<=10000; ++i){ if(i%4==0 && i%100!=0) is[i]=366; else if(i%400==0) is[i]=366; else is[i]=365; } } int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int T;cin>>T; init(); while(T--){ int y,mm,dd,d=0,f=0,ff=0; char c; cin>>y>>c>>mm>>c>>dd; if(mm>2) f=1; if(mm==2 && dd==29) f=1, ff=1; for(int i=y; i<=10000; ++i){ d+=is[i+f]; //cout<<is[i+f]<<"UUU\n"; d%=7; if(ff){ if(d==0 && is[i+1]==366){ cout<<i+1<<endl; break; } } else if(d==0){ cout<<i+1<<endl; break; } } } return 0; }
时间: 2024-10-12 15:53:08