找规律
日期小助手
http://www.nowcoder.com/questionTerminal/1f12bf67d436473ca4ac1bbc967ca4ad
#include<iostream> #include<algorithm> #include<cstring> #include<cmath> using namespace std; typedef long long ll; const int MAX = 110; int a[MAX] = {14}; int b[MAX] = {18}; int main () { int m; for (int i = 1; i < MAX; ++i) { if (i%4 == 0 && i%100 != 0) { a[i] = a[i-1]-2; b[i] = b[i-1]-2; } else { a[i] = a[i-1]-1; b[i] = b[i-1]-1; } if (a[i] < 8) a[i] += 7; if (b[i] < 15) b[i] += 7; } cin >> m; while (m--) { int n,y,t; cin >> n >> y >> t; if (y < 5) { printf("Mother's Day: May %dth, %d\n", a[n-2000], n); } else if (y > 6) { printf("Mother's Day: May %dth, %d\n", a[n+1-2000], n+1); } else if (y == 5) { if (t < a[n-2000]) printf("Mother's Day: May %dth, %d\n", a[n-2000], n); else { if (b[n-2000] == 21) printf("Father's Day: June %dst, %d\n", b[n-2000], n); else printf("Father's Day: June %dth, %d\n", b[n-2000], n); } } else if (y == 6) { if (t < b[n-2000]) { if (b[n-2000] == 21) printf("Father's Day: June %dst, %d\n", b[n-2000], n); else printf("Father's Day: June %dth, %d\n", b[n-2000], n); } else printf("Mother's Day: May %dth, %d\n", a[n+1-2000], n+1); } } return 0; } // 找规律题解