`
xiaoheliushuiya
  • 浏览: 403671 次
文章分类
社区版块
存档分类
最新评论

2013金山西山居创意游戏程序挑战赛——初赛(3)生日猜猜猜

 
阅读更多

这道题是水题。


#include<iostream>
using namespace std;

int leapYear(int n){
    if(((n % 4 == 0)&&(n % 100))||(n % 400 == 0))
           return 1;
    return 0;
}

int gcd(int a,int b){
     int r;
     while(a%b)
    {
         r=a%b;
         a=b;
         b=r;
    }
    return  b;
}

int main(){
    int t,x,y,z;
    int index_x,index_y;
    int i,j,k,count,tmp=1;
    cin>>t;
    while(t--){
          int g;
          cin>>x>>y>>z;
          cout<<"Case #"<<tmp++<<": ";
          count=0;
          
          for(i=1;i<=12;i++){
              if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
                     k=31;
              }
              else if(i==4||i==6||i==9||i==11){
                     k=30;
              }
              else{
                     leapYear(z)?k=29:k=28;  
              }
               for(j=1;j<=k;j++){
                    g=i>j?gcd(i,j):gcd(j,i);             
                    if(x==g&&y==i*j/g){
                         index_y=i;
                         index_x=j;
                         count++;                     
                         }               
               }        
          }
         if(count==0)
             cout<<"-1"<<endl;
         else if(count==1)
             printf("%d/%02d/%02d\n",z,index_y,index_x);
         else
             cout<<"1"<<endl;    
    }
    return 0;
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics