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. rsync同步操作命令

    在本地磁盘同步数据 将/home做个备份 # rsync -a --delete /home /backups -a 归档模式,表示以递归方式传输文件, -delete 删除那些接收端还有而发送端已经 ...

  2. [Codeforces 757E] Bash Plays with Functions (数论)

    题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...

  3. Classes and functions

    As another example of a user-defined type, we’ll define a class called Time that records the time of ...

  4. 33.unique_ptr独享内存智能指针

    #include <iostream> #include <memory> #include <string> #include <vector> us ...

  5. Linux LVM在线扩容

    环境: 虚拟化环境,SUSE Linux Enterprise Server 11sp3,直接把虚拟磁盘从100G改成150G. 现有的LVM是100G,/home 的LV需要再加50G. 步骤: f ...

  6. Python组织文件 实践:将文件的不同版本备份为ZIP文件

    功能:备份文件夹.能将文件的不同版本备份下来,并且每个有不同的名字 #! python3 # backupToZip.py - 备份文件的不同版本到压缩文件中 import zipfile,os #f ...

  7. Unity C# 关于设计模式的思考

    一.当你的项目发现有如下问题之一时,就需要考虑重构代码,可能会有某种模式适合. 1.代码无法进行单元测试. 2.需求的变动总是导致代码的变动. 3.有重复代码的存在. 4.继承层次过多. 5.隐藏的依 ...

  8. docker安装cloudera manager,切换cloudera-scm用户报错can not open session

    在root帐号下su - cloudera-scm报错can not open session 在网上搜,大概是说ulimit超过限制之类,搞了很久才找到/etc/security/limits.d/ ...

  9. C# Winform利用POST传值方式模拟表单提交数据(Winform与网页交互)

    其原理是,利用winfrom模拟表单提交数据.将要提交的參数提交给网页,网页运行代码.得到数据.然后Winform程序将网页的全部源码读取下来.这样就达到windows应用程序和web应用程序之间传參 ...

  10. Ubuntu14环境下minigui安装问题记录--object.lo错误

    minigui3.0.12在Ubuntu14上面编译只是去?出现这个错误:object.h:275:9: error: incompatible types when assigning to typ ...