题目链接:
https://ac.nowcoder.com/acm/contest/5278/F
思路:
找规律发现母亲节出现的日期在8-14之间,若x<8则x=(x+7)%15,父亲节出现的日期在15-21之间,
若x<15则x=(x+7)%22,赛时忘记掉2100年不是闰年了真的找bug找吐了
代码:
#include <bits/stdc++.h> #include <iomanip> typedef long long ll; using namespace std; const int INF=0x7fffffff; const int MAXN=2e5+5; int a[200],b[200]; int main() { int t;scanf("%d",&t); a[0]=14;int ti=14,i=1; while(i<=102) { if(i%4==0&&i!=100) ti-=2; else ti-=1; if(ti<8) ti=(ti+7)%15; a[i]=ti; i++; } ti=18,i=1;b[0]=18; while(i<=102) { if(i%4==0&&i!=100) ti-=2; else ti-=1; if(ti<15) ti=(ti+7)%22; b[i]=ti; i++; } while(t--) { int y,m,d; scanf("%d%d%d",&y,&m,&d); if(m>6||(m==6&&d>=b[y-2000])) { printf("Mother's Day: May %dth, %d ",a[y+1-2000],y+1); } else if(m<5||(m==5&&d<a[y-2000])) { printf("Mother's Day: May %dth, %d ",a[y-2000],y); } else if(m==5&&d>=a[y-2000]||(m==6&&d<b[y-2000])) { printf("Father's Day: June %d",b[y-2000]); if(b[y-2000]==21) printf("st, %d ",y); else printf("th, %d ",y); } } return 0; }