HDU 4551 生日猜猜猜(简单题)

生日猜猜猜

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 460    Accepted Submission(s): 176


Problem Description
小明对生日十分看重,因为他可以得到祝福,可以和朋友亲人一起分享快乐,可以为自己的人生做一次总结,并且...能够收到好多礼物!
不过小明是个神秘的人,不会轻易告诉你他的生日,现在他想到一个办法,让你去猜他的生日是哪一天。

小明会告诉你如下三个信息:

1. 出生月份和出生日子的最大公约数;
2. 出生月份和出生日子的最小公倍数;
3. 出生年份;

现在要求你猜出小明的生日。
 

 

Input
第一行输入一个正整数T,表示总共有T组册数数据(T <= 200);
对于每组数据依次输入三个数x,y,z,
x表示出生月份和出生日子的最大公约数(1<= x <=1000);
y表示出生月份和出生日子的最小公倍数(1<= y <=1000);
z表示出生年份(1900 <= z <= 2013)。
每组输入数据占一行。
 

 

Output
对于每组数据,先输出Case数。
如果答案不存在 ,输出“-1”;
如果答案存在但不唯一 ,输出“1”;
如果答案唯一,输出生日,日期格式为YYYY/MM/DD;
每组输出占一行,具体输出格式参见样例。
 

 

Sample Input
3 12 24 1992 3 70 1999 9 18 1999
 

 

Sample Output
Case #1: 1992/12/24 Case #2: -1 Case #3: 1999/09/18
 

 

Source
 

 

Recommend
liuyiding
 
 
 
很简单的水题
 
//============================================================================
// Name        : A.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#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);
    int x,y,z;
    int T;
    scanf("%d",&T);
    int iCase=0;
    while(T--)
    {
        iCase++;
        scanf("%d%d%d",&x,&y,&z);
        printf("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)printf("-1\n");
        else if(ans>1)printf("1\n");
        else printf("%d/%02d/%02d\n",z,ansm,ansd);
    }

    return 0;
}

 

 

posted on 2013-05-20 19:23  kuangbin  阅读(840)  评论(0编辑  收藏  举报

导航

JAVASCRIPT: