您的位置:首页 > 其它

UVA 725

2015-07-28 10:31 190 查看
Description





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

. 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


题意:输入一个数n,从小到大输出它的abcde / fghij = n的类型的式子(注意空格,可以有前导0)a-j是一个0到9的排列。如果没有则输出There are no solutions for 61. 格式要求:每测试一组案例,换一空行。(这输出格式也是RLGL)

解题思路:枚举,但是是从被除数枚举,通过相乘算出除数。然后就只需要判断除数是否大于100000,a-j是否相等。

代码如下:(本来想自己写的,就是自己不会用标记,最后还是没有坚持下来,还是看了别人的博客,然后仿写了。)

想问个问题,用 memse(m,0,sizeof(m)) 清零数组m,为什么一定是sizeof(m), 不可以用m的长度10,因为当我用10的时候就连案例都通不过了....

求告知,没错我就是这么菜.....(⊙﹏⊙)b

#include <stdio.h>
#include <cstring>
int m[10];
int panduan(int a,int b)
{
if(a>100000)
return 0;
memset(m,0,sizeof(m));
//for(int i=0;i<10;i++)
//  m[i]=0;
if(b<10000)
m[0];       //容易忘记     while(a)
{
m[a%10]=1;  //每一位都标记
a=a/10;     //标记了就除掉一位
}
while(b)
{
m[b%10]=1;
b=b/10;
}
int sum=0;
for(int j=0; j<10; j++)
sum+=m[j];
return sum==10;    //当sum等于10才返回
}
int main()
{
int n,k=0;
while(scanf("%d",&n)==1&&n)
{
if(k>0) printf("\n"); k++;   //输出格要求
int flag=1;
for(int i=1234; i<1000000; i++)
{
if(panduan(n*i,i))
{
printf("%d / %05d = %d\n",i*n,i,n);
flag=0;
}
}
if(flag)
printf("There are no solutions for %d.\n",n);

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: