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的表达式,当中a~j恰好为数字0~9的一个排列(能够有0前导)
思路:
枚举fghij就能够算出abcde,然后推断符不符合条件。
代码:
#include<cstdio>
using namespace std;
int main()
{
int i,j,k,l,m,a,b;
int b1,b2,b3,b4,b5;
int flag;
int N;
int casex=0;
while(scanf("%d",&N)&&N)
{
if(casex++) printf("\n");
flag=0;
for( i=0;i<=9;i++)
for(j=0;j<=9;j++)
for(k=0;k<=9;k++)
for(l=0;l<=9;l++)
for(m=0;m<=9;m++)
{
if(i!=j&&i!=k&&i!=l&&i!=m&&j!=k&&j!=l&&j!=m&&k!=l&&k!=m&&l!=m)
a=i*10000+j*1000+k*100+l*10+m;
else continue;
b=N*a;
if(b>99999)
continue;
b1=b/10000;
b2=b%10000/1000;
b3=b%10000%1000/100;
b4=b%10000%1000%100/10;
b5=b%10;
if(b1!=b2&&b1!=b3&&b1!=b4&&b1!=b5&&b2!=b3&&b2!=b4&&b2!=b5&&b3!=b4&&b3!=b5&&b4!=b5&&b1!=i&&b1!=j&&b1!=k&&b1!=l&&b1!=m&&b2!=i&&b2!=j&&b2!=k&&b2!=l&&b2!=m&&b3!=i&&b3!=j&&b3!=k&&b3!=l&&b3!=m&&b4!=i&&b4!=j&&b4!=k&&b4!=l&&b4!=m&&b5!=i&&b5!=j&&b5!=k&&b5!=l&&b5!=m)
{
printf("%d / %d%d%d%d%d = %d\n",b,i,j,k,l,m,N);
flag=1;
}
else
continue; } if(!flag) printf("There are no solutions for %d.\n",N); }
return 0; }

 

Miguel Revilla

2000-08-31

uva725(除法)的更多相关文章

  1. UVA725 Division 除法【暴力】

    题目链接>>>>>> 题目大意:给你一个数n(2 <= n <= 79),将0-9这十个数字分成两组组成两个5位数a, b(可以包含前导0,如02345 ...

  2. 7_1 除法(UVa725)<选择合适的枚举对象>

    如果把数字0到9分配成2个整数(各五位数),现在请你写一支程序找出所有的配对使得第一个数可以整除第二个数,而且商为N(2<=N<=79),也就是:abcde / fghijk = N这里每 ...

  3. [LeetCode] Evaluate Division 求除法表达式的值

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

  4. Java BigDecimal 转换,除法陷阱(转)

    源地址:   http://blog.csdn.net/niannian_315/article/details/24354251 今天在用BigDecimal“出现费解”现象,以前虽然知道要避免用, ...

  5. SQL 的坑1 除法“”不可用“”

    今天工作中遇见 一问题,有5各部分,现要求5个部分各自的比例,SQL语句没有问题,后来还试了"加","减","乘","Round& ...

  6. Python学习---除法

    python有两种除法,普通除法 a/b ,不论a,b精度 得到的都是浮点数. 4/2 = 2.0    3/5 = 0.6 floor除法,a//b , 得到一个舍弃小数位的整数结果,所以结果永远是 ...

  7. 【Python】一、除法问题及基本操作(逻辑与,if替代switch)及支持中文打印

    1.查看版本 C:\Users\XXX>python -V Python 2.7.1 2.除法问题(不要整除) from __future__ import division tmp=0x3ec ...

  8. 除法取模练习(51nod 1119 & 1013 )

    题目:1119 机器人走方格 V2 思路:求C(m+n-2,n-1) % 10^9 +7       (2<=m,n<= 1000000) 在求组合数时,一般都通过双重for循环c[i][ ...

  9. HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)

    传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...

随机推荐

  1. storm集群安装配置

    1.上传解压 2.进入到storm的conf目录 接上图 启动三台节点的zookeeper集群 启动和查看 Storm 在 nimbus.host 所属的机器上启动 nimbus 服务和 logvi ...

  2. [转]Adobe Creative Cloud 2015 下载 Adobe CC 2015 Download

    Adobe Creative Cloud 2015 下载   Adobe 宣布 Creative Cloud 设计套件全线更新! Adobe CC 2015新功能包括: – Premiere Pro ...

  3. Android5.0之后的页面切换动画

    Android5.0之后给我们开发者剩了好多的事情,为什么这么说呢?还记得刚开始的时候,Android里面的所有的动画都要我们开发者自己来写,现在不需要了,因为5.0之后自带了好多的动画,比如:按钮点 ...

  4. Linux下安装使用MySQL

    网上找那些安装教程比较多的版本,版本只要不是太旧就行. 下载mysql 5.6.28 通用版64位二进制版,二进制版相当于windows的安装包,可以直接安装,如果是源码版,还需要编译后再进行安装. ...

  5. mybatis-generator-core快速生成实体类和Mapper

    日常使用Mybatis少不了和实体类和 Mapper 打交道.除了我们手写来实现,还可以使用 mybatis-generator-core 来快速生成 实体类和 Mapper. 步骤如下: 1.下载 ...

  6. 转载 :Linux有问必答:如何在Debian或Ubuntu上安装完整的内核源码

    http://linux.cn/article-5015-1.html 问题:我需要为我的Debian或Ubuntu下载并安装完整树结构的内核源码以供编译一个定制的内核.那么在Debian或Ubunt ...

  7. mysql(for update)悲观锁总结与实践

    悲观锁,正如其名,它指的是对数据被外界(包括本系统当前的其他事务,以及来自外部系统的事务处理)修改持保守态度,因此,在整个数据处理过程中,将数据处于锁定状态.悲观锁的实现,往往依靠数据库提供的锁机制( ...

  8. Log4j2打印一行日志时返回本行日志的字符串

    import org.apache.logging.log4j.Level; import org.apache.logging.log4j.core.impl.Log4jLogEvent; impo ...

  9. jsp静态引入(<%@ include file=""%>) 乱码问题

    在web.xml中的web-app中加入这段话: <jsp-config> <jsp-property-group> <display-name>JSPConfig ...

  10. 【 D3.js 入门系列 --- 2.1 】 关于怎样选择,插入,删除元素

    本人的个人博客首页为: http://www.ourd3js.com/  ,csdn博客首页为:http://blog.csdn.net/lzhlzz/. 转载请注明出处,谢谢. 在D3.js中,选择 ...