我是靠谱客的博主 标致航空,最近开发中收集的这篇文章主要介绍UVA-725 Division,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where 2 ≤ N ≤ 79. That is, abcde /fghij = N where each letter represents a different digit. The first digit of one of the numerals is allowed to be zero.

Input
Each line of the input file consists of a valid integer N. An input of zero is to terminate the program.

Output
Your program have to display ALL qualifying pairs of numerals, sorted by increasing numerator (and, of course, denominator). Your output should be in the following general form: xxxxx / xxxxx = N xxxxx / xxxxx = N . .
In case there are no pairs of numerals satisfying the condition, you must write ‘There are no solutions for N.’. Separate the output for two different values of N by a blank line.
Sample Input
61
62
0

Sample Output
There are no solutions for 61.
79546 / 01283 = 62 94736 / 01528 = 62

分析:暴力枚举。技巧:除数从1234开始枚举,被除数为除数乘以n,在判断是否用到0~9各一次。

Source:

#include<stdio.h>
#include<string.h>
int n,found;
int num[10]={0};
int main()
{
    int x,y,a,b;
    int i,t=0;
    while(scanf("%d",&n)!=EOF&&n!=0)
    {
        if(t++)
            printf("n");
        found=0;
        for(x=1234;x<=86420;x++)
        {
            memset(num,0,sizeof(num));
            y=x*n;
            if(y>98765)
                break;
            a=x;b=y;
            for(i=1;i<=5;i++)
            {
                num[a%10]++;
                num[b%10]++;
                a/=10;
                b/=10;
            }
            for(i=0;i<10;i++)
            {
                if(num[i]==0||num[i]>1)
                    break;
            }
            if(i==10)
            {
                printf("%05d / %05d = %dn",y,x,n);
                found=1;
            }
        }
        if(!found)
            printf("There are no solutions for %d.n",n);
    }
    return 0;
}

最后

以上就是标致航空为你收集整理的UVA-725 Division的全部内容,希望文章能够帮你解决UVA-725 Division所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(31)

评论列表共有 0 条评论

立即
投稿
返回
顶部