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 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 分析:如果将abcde与fghij都枚举出来会超时,所以只枚举fghij再用N乘以它就可以得到abcde,在判断a-j中各个数字都不同就可以了。
#include <iostream>
#include <cstdio>
using namespace std;
int used[10];
int image(int x,int y)
{
if(y>98765)
return 0;
for(int i=0;i<10;i++)
used[i]=0;
if(x<10000)
used[0]=1;
while(x)
{
used[x%10]=1;
x/=10;
}
while(y)
{
used[y%10]=1;
y/=10;
}
int sum=0;
for(int i=0;i<10;i++)
sum+=used[i];
return (sum==10); }
int main()
{
int n,t=0;
while(scanf("%d",&n)==1&&n)
{
int flag=0;
if(t++)
printf("\n");
for(int i=1234;i<100000;i++)
{
if(image(i,i*n))
{
printf("%05d / %05d = %d\n",i*n,i,n);
flag=1; }
}
if(!flag)
printf("There are no solutions for %d.\n",n);
}
}

Program A - 暴力求解的更多相关文章

  1. Program C 暴力求解

    Description   A ring is composed of n (even number) circles as shown in diagram. Put natural numbers ...

  2. Program L 暴力求解

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  3. Program B 暴力求解

    Given a sequence of integers S = {S1,S2,...,Sn}, you should determine what is the value of the maxim ...

  4. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  5. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  6. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  7. BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~

    jrMz and angle       Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Other ...

  8. hdu6570Wave (暴力求解)

    Problem Description Avin is studying series. A series is called "wave" if the following co ...

  9. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

随机推荐

  1. ajax上传文件,并检查文件类型、检查文件大小

    1.使用ajaxfileupload.js的插件,但是对插件做了一处修改,才能够正常使用 修改的部分如下: uploadHttpData: function (r, type) { var data ...

  2. 上传本地文件到HDFS

    源代码: import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hado ...

  3. 转!JNDI 是什么?

    JNDI是 Java 命名与目录接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之一,不少专家认为,没有透彻理解JNDI的意义和作用,就没有 ...

  4. Lua 栈中元素的位置

    Lua与C.C#等的交互是通过栈来实现的,每次插入元素都是放在栈顶(top),至于元素的index,可以使用正数和负数两种方式, 如取栈底开始至第index个元素 -index = gettop - ...

  5. Windows CPU占用率过高

    今天调试程序,发现Windows7的CPU占用率一直为25%左右,如下图所示.四核25%,换成单核那就是100%的占用率了! 上图进入"进程"页面,单击"CPU" ...

  6. 例题:输入您的出生日期,判断你的星座,主要练习使用datetime类及if else语句。很实用

    while (true) { Console.WriteLine("请输入您的生日(年-月-日)");//提示输入 string x = Console.ReadLine();// ...

  7. 20145218 《Java程序设计》第五周学习总结

    20145218 <Java程序设计>第五周学习总结 教材学习内容总结 异常 程序中总有些意想不到的状况所引发的错误,如果不对异常进行正确的处理,则可能导致程序的中断执行,造成不必要的损失 ...

  8. [Hadoop 周边] 浅谈大数据(hadoop)和移动开发(Android、IOS)开发前景【转】

    原文链接:http://www.d1net.com/bigdata/news/345893.html 先简单的做个自我介绍,我是云6期的,黑马相比其它培训机构的好偶就不在这里说,想比大家都比我清楚: ...

  9. [myeclipse] 官方中文网站

    myeclipse官方中文网站:http://www.myeclipsecn.com/

  10. 分享一个快速的Json(反)序列化开源项目 Jil

    我们不缺少JSON的序列化库,但我们缺少一个性能非常好的库,这对于网站来说非常重要.今天我发现了Jil. 他是开源的代码: https://github.com/kevin-montrose/Jil ...