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. [Atcoder Grand 006 C] Rabbit Exercise 解题报告 (期望)

    题目链接:https://www.luogu.org/problemnew/show/AT2164 https://agc006.contest.atcoder.jp/tasks/agc006_c 题 ...

  2. Chrome插件开发笔记

    使用 XMLHttpRequest来抓取盗版小说网站里面的内容,但是注意需要在manifest.json文件中设置permission var xhr = new XMLHttpRequest();x ...

  3. global_step

    global_step=tf.Variable(0, trainable=False) 设定trainable=False 可以防止该变量被数据流图的 GraphKeys.TRAINABLE_VARI ...

  4. 同门不同类—创新Aurvana Live2/Air简评(附随身视听设备心路历程)

    (注,本文把live2/air并成一起写的,同时本人是木耳,请轻拍) 本命年各种坏东西,很是无语,终于坏到耳塞耳机了来了,之前用的拜亚DT235无缘无故就一边不响了,无奈只能扔了. 纠结了好几个月,终 ...

  5. sql查询 按照规定的顺序返回结果集。

    DECODE函数 oracle 独有,功能强大.相当于 if else if IF 条件=值1 THEN RETURN(翻译值1)ELSIF 条件=值2 THEN RETURN(翻译值2) ..... ...

  6. Unity C# 设计模式(六)原型模式

    定义:用原型实例指定创建对象的种类,并通过拷贝这些原型来创建新的对象. 优点: 1.原型模式向客户隐藏了创建新实例的复杂性 2.原型模式允许动态增加或较少产品类. 3.原型模式简化了实例的创建结构,工 ...

  7. Android输入法扩展之远程输入法

    近年来,互联网电视開始火热,乐视TV,小米TV,近期爱奇艺也在大肆的招人做爱奇艺电视.当然还有更被关注的苹果电视.事实上,这个趋势非常正常,也非常合理,传统单纯的接收电视节目的电视已经太传统了.是该被 ...

  8. 解析XML文件之使用DOM解析器

    在前面的文章中.介绍了使用SAX解析器对XML文件进行解析.SAX解析器的长处就是占用内存小.这篇文章主要介绍使用DOM解析器对XML文件进行解析. DOM解析器的长处可能是理解起来比較的直观,当然, ...

  9. C++归并算法

    #include <iostream> using namespace std; void DealWhat(int ar[],int start,int end,int b[]) { i ...

  10. BZOJ5204: [CodePlus 2018 3 月赛]投票统计

    [传送门:BZOJ5204] 简要题意: 有n个选手,每个选手会选择一道题投票,求出投票最多的题目个数和这些题目的编号,如果所有题目的投票数相同,则输出-1 题解: 直接搞 离散化,然后判断就可以了 ...