hdoj 4551 生日猜猜猜

题目链接

//hdoj 4551
//2013-05-26-20.52
#include <stdio.h>
int day[2][13]  = {{0,31,28,31,30,31,30,31,31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}};

int judge(int y)
{
    if (y%4 == 0 && y % 100 != 0 || y % 400 == 0)
        return 1;
    else
        return 0;
}

int gcd(int x, int y)
{
    if (x%y == 0)
        return y;
    else
        return gcd(y, x%y);
}

int main()
{
    int x, y, z;
    int t;
    scanf("%d" ,&t);
    for (int k = 1; k <= t; k++)
    {
        scanf("%d %d %d", &x, &y, &z);
        int year = judge(z);
        int a, b;
        int cnt = 0;
        for (int i = 1; i <= 12; i++)
        {
            for (int j = 1; j <= day[year][i]; j++)
            {
                if (gcd(i, j) == x && i*j/gcd(i, j) == y)
                {
                    a = i, b = j;
                    cnt++;
                }
            }
        }
        if (cnt == 0)
            printf("Case #%d: -1\n", k);
        else if (cnt > 1)
            printf("Case #%d: 1\n", k);
        else
            printf("Case #%d: %04d/%02d/%02d\n", k, z, a, b);
    }
    return 0;
}


发布了236 篇原创文章 · 获赞 577 · 访问量 52万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 猿与汪的秘密 设计师: 上身试试

分享到微信朋友圈

×

扫一扫,手机浏览