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

 
 

UVA 725的更多相关文章

  1. 暴力枚举 UVA 725 Division

    题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...

  2. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

  3. 除法(Division ,UVA 725)-ACM集训

    参考:http://www.cnblogs.com/xiaobaibuhei/p/3301110.html 算法学到很弱,连这么简单个问题都难到我了.但我偏不信这个邪,终于做出来了.不过,是参照别人的 ...

  4. uva 725 Division(除法)暴力法!

    uva 725  Division(除法) A - 暴力求解 Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & ...

  5. UVA.725 Division (暴力)

    UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...

  6. UVA 725 UVA 10976 简单枚举

    UVA 725 题意:0~9十个数组成两个5位数(或0开头的四位数),要求两数之商等于输入的数据n.abcde/fghij=n. 思路:暴力枚举,枚举fghij的情况算出abcde判断是否符合题目条件 ...

  7. Uva 725 Division

    0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...

  8. uva 725 division(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A

  9. Uva 725 除法

    紫书P182 直接枚举 0~9 的全排列会超时,枚举fghij就可以了,计算出 abcde ,这里有一个新的函数,也可以不用咯,把每一位数据提取出来,while循环可以做到,这里的新的函数是,spri ...

随机推荐

  1. oracle11g asm standalone 单实例重建

    原文地址:oracle11g asm单实例重建has 作者:datapeng 最近到客户那里处理故障,客户说,他们修改了一下hostname,导到has出现了问题,当然,他们的数据库也就无法再启动,把 ...

  2. oracle锁

    1.概念 数据库中有两种基本的锁类型:排它锁(Exclusive Locks,即X锁)和共享锁(Share Locks,即S锁). 当数据对象被加上排它锁时,其他的事务不能对它读取和修改:加了共享锁的 ...

  3. Windows 8.1 归档 —— Step 1 选择与安装

    下面是 Windows 8.1 各版本区别: Windows 8.1 标准版(一般就称之为Windows 8.1): 包括全新的 Windows 商店.Windows 资源管理器.任务管理器等等,还将 ...

  4. Jersey(1.19.1) - Client API, Uniform Interface Constraint

    The Jersey client API is a high-level Java based API for interoperating with RESTful Web services. I ...

  5. Spring(3.2.3) - Beans(12): 属性占位符

    使用属性占位符可以将 Spring 配置文件中的部分元数据放在属性文件中设置,这样可以将相似的配置(如 JDBC 的参数配置)放在特定的属性文件中,如果只需要修改这部分配置,则无需修改 Spring ...

  6. Linux 命令 - crontab: 任务调度

    cron 是一个 Linux 下的定时执行工具,可以在无需人工干预的情况下运行作业.守护进程 cron 会读取 crontab 文件,根据配置在指定的时间执行任务.contab 命令用来添加.删除.显 ...

  7. 安装安卓模拟器和unity3d插件EZGUI

    一.安装安卓模拟器 1.下载安卓模拟器http://www.pc6.com/softview/SoftView_64923.html: 2.安装安卓模拟器. 3.下载安卓apk,然后右键用BlueSt ...

  8. HDOJ2007平方和与立方和

    平方和与立方和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Sub ...

  9. 老男孩-金角大王-python学习博客地址

    http://www.cnblogs.com/alex3714/category/770733.html

  10. 动态sql语句基本语法

    1 普通sql语句可以用exec执行,如: SELECT * FROM video EXEC ('SELECT * FROM video') EXEC sp_executesql N'SELECT * ...