第一个题就不说了,注意闰年的2月29。
1 #include <map> 2 #include <set> 3 #include <list> 4 #include <queue> 5 #include <stack> 6 #include <cmath> 7 #include <ctime> 8 #include <vector> 9 #include <bitset> 10 #include <cstdio> 11 #include <string> 12 #include <numeric> 13 #include <cstring> 14 #include <cstdlib> 15 #include <iostream> 16 #include <algorithm> 17 #include <functional> 18 using namespace std; 19 typedef long long ll; 20 typedef unsigned long long ull; 21 22 int dx[4]={-1,1,0,0}; 23 int dy[4]={0,0,-1,1};//up down left right 24 bool inmap(int x,int y,int n,int m){if(x<1||x>n||y<1||y>m)return false;return true;} 25 int hashmap(int x,int y,int m){return (x-1)*m+y;} 26 27 #define eps 1e-8 28 #define inf 0x7ffffff 29 #define debug puts("BUG") 30 #define lson l,m,rt<<1 31 #define rson m+1,r,rt<<1|1 32 #define read freopen("in.txt","r",stdin) 33 #define write freopen("out.txt","w",stdout) 34 #define maxn 1005 35 int d[15]={0,31,28,31,30,31,30,31,31,30,31,30,31}; 36 int cnt[maxn][maxn]; 37 struct str 38 { 39 int m,d; 40 }nd[maxn][maxn]; 41 bool isY(int y) 42 { 43 if(y%400==0)return true; 44 if(y%100==0)return false; 45 return y%4==0; 46 } 47 int gcd(int a,int b) 48 { 49 if(b==0)return a; 50 return gcd(b,a%b); 51 } 52 void init() 53 { 54 memset(cnt,0,sizeof(cnt)); 55 for(int i=1;i<13;++i) 56 { 57 for(int j=1;j<=d[i];++j) 58 { 59 int t=gcd(i,j),t2=i*j/t; 60 ++cnt[t][t2]; 61 nd[t][t2].m=i,nd[t][t2].d=j; 62 } 63 } 64 } 65 int main() 66 { 67 //read; 68 int cas; 69 init(); 70 scanf("%d",&cas); 71 for(int xx=1;xx<=cas;++xx) 72 { 73 int a,b,y; 74 scanf("%d%d%d",&a,&b,&y); 75 if(isY(y)&&a==1&&b==58) 76 printf("Case #%d: %04d/%02d/%02d\n",xx,y,2,29); 77 else 78 { 79 if(cnt[a][b]==0) 80 printf("Case #%d: -1\n",xx); 81 else if(cnt[a][b]>1) 82 printf("Case #%d: 1\n",xx); 83 else printf("Case #%d: %04d/%02d/%02d\n",xx,y,nd[a][b].m,nd[a][b].d); 84 } 85 } 86 return 0; 87 }