码迷,mamicode.com
首页 > 其他好文 > 详细

UVa 725 Division --- 简单枚举

时间:2015-12-17 20:46:55      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666 

 

 

/* UVa 725 Division --- 简单枚举 */
#include <cstdio>
#include <cstring>

bool used[10];

/* 判断传进来的两个数是否满足条件 */
bool judge(int a, int b)
{
    if (a > 98765)
        return 0;
    memset(used, 0, sizeof used);
    if (b < 10000)
        used[0] = 1;
    while (b){
        used[b % 10] = 1;
        b /= 10;
    }
    while (a){
        used[a % 10] = 1;
        a /= 10;
    }
    int sum = 0;
    for (int i = 0; i < 10; ++i)
        sum += used[i];
    return sum == 10;
}

int main()
{
    int n, kase = 0;

    while (scanf("%d", &n)== 1 && n){
        if (kase++){
            printf("\n");
        }
        int cnt = 0;
        for (int i = 1234; i <= 54321; ++i){
            if (judge(i*n, i)){
                printf("%05d / %05d = %d\n", i*n, i, n);
                ++cnt;
            }
        }//for(i)
        if (cnt == 0){
            printf("There are no solutions for %d.\n", n);
        }
    }

    return 0;
}

 

UVa 725 Division --- 简单枚举

标签:

原文地址:http://www.cnblogs.com/tommychok/p/5055021.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!