zoukankan      html  css  js  c++  java
  • 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;
    }
     
    人一我百!人十我万!永不放弃~~~怀着自信的心,去追逐梦想
  • 相关阅读:
    快速找到由程序员到CTO发展道路上的问路石
    从大师身上反思
    你真的了解企业虚拟化吗?
    “驱网核心技术丛书”创作团队访谈
    程序员到CTO需要准备什么
    深入搜索引擎的关键——索引
    程序员到CTO必须注意的几个关键点
    微软全球MVP教你如何规划程序人生
    “碟中碟”虚拟光驱软件开发者——万春 读《寒江独钓——Windows内核安全编程 》有感
    常用jar包之commonscollection使用
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3089194.html
Copyright © 2011-2022 走看看