#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <map> #include <queue> #include <set> #include <vector> #include <string> #include <math.h> using namespace std; int gcd(int a,int b) { if(b==0)return a; return gcd(b,a%b); } int day[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool check(int y,int m,int d) { if(m>12)return false; if(m==2) { if( y%400==0 || (y%100!=0&&y%4==0 ) ) { if(d>29)return false; } else { if(d>28)return false; } } else { if(d>day[m])return false; } return true; } int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); FILE *fp; FILE *fo; if((fp=fopen("F:\\promble3\\frist.txt","r"))==NULL) { printf("Error\n"); return 0; } if((fo=fopen("F:\\promble3\\frist_answer.txt","w"))==NULL) { printf("Error\n"); return 0; } int x,y,z; int T; fscanf(fp,"%d",&T); int iCase=0; while(T--) { iCase++; fscanf(fp,"%d%d%d",&x,&y,&z); fprintf(fo,"Case #%d: ",iCase); int tmp=x*y; int ans=0; int ansm,ansd; for(int i=1;i<=12;i++) { if(tmp%i)continue; int temp=tmp/i; if(gcd(i,temp)==x && check(z,i,temp)) { ans++; ansm=i; ansd=temp; } } if(ans==0)fprintf(fo,"-1\n"); else if(ans>1)fprintf(fo,"1\n"); else fprintf(fo,"%d.%02d.%02d\n",z,ansm,ansd); } return 0; } |
Double click to view unformatted code.