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. [Codeforces Round #194 (Div. 2)] Secret 解题报告 (数学)

    题目链接:http://codeforces.com/problemset/problem/334/C 题目: 题目大意: 给定数字n,要求构建一个数列使得数列的每一个元素的值都是3的次方,数列之和S ...

  2. Scala基础简述

    * Scala基础简述 本文章作为Scala快速学习的教程,前提环境是:我假设在此之前,你已经学会了Java编程语言,并且我们以随学随用为目标(在此不会深度挖掘探讨Scala更高级层次的知识).其中语 ...

  3. hadoop ha

    https://blog.csdn.net/daydayup_668819/article/details/70815335 https://www.jianshu.com/p/8a6cc2d7206 ...

  4. html局部页面打印

    1.局部打印函数. function preview(oper) { if (oper < 10) { bdhtml=window.document.body.innerHTML;//获取当前页 ...

  5. 瞎折腾-CentOS 7.4 编译4.16.2版kernel 并安装

    CentOS 7.4下 原内核版本: 3.10.0-693.el7.x86_64 改后内核版本: 4.16.2 系统版本: CentOS-7-x86_64-Minimal-1708.iso 运行环境: ...

  6. 紫书 例题 10-21 UVa 11971(连续概率)

    感觉这道题的转换真的是神来之笔 把木条转换成圆,只是切得次数变多一次 然后只要有一根木条长度为直径就租不成 其他点的概率为1/2^k 当前这个点的有k+1种可能 所以答案为1 - (k+1)/2^k ...

  7. C#调用C/C++动态库,封装各种复杂结构体

    C#调用C/C++动态库,封装各种复杂结构体. 标签: c++结构内存typedefc# 2014-07-05 12:10 6571人阅读 评论(1) 收藏 举报  分类: C(8)  C#(6)  ...

  8. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

  9. bzoj1066【SCOI2007】蜥蜴

    1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec  Memory Limit: 162 MB Submit: 2512  Solved: 1238 [Submit][Statu ...

  10. mahout处理路透社语料步骤,转换成须要的格式

    首先下载路透社语料(百度就能够下载): 然后上传Linux 并解压到指定文件夹.Tips:此处我放在可 /usr/hadoop/mahout/reutersTest/reuters tar -zxvf ...