uva725(除法)
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(除法)的更多相关文章
- UVA725 Division 除法【暴力】
题目链接>>>>>> 题目大意:给你一个数n(2 <= n <= 79),将0-9这十个数字分成两组组成两个5位数a, b(可以包含前导0,如02345 ...
- 7_1 除法(UVa725)<选择合适的枚举对象>
如果把数字0到9分配成2个整数(各五位数),现在请你写一支程序找出所有的配对使得第一个数可以整除第二个数,而且商为N(2<=N<=79),也就是:abcde / fghijk = N这里每 ...
- [LeetCode] Evaluate Division 求除法表达式的值
Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...
- Java BigDecimal 转换,除法陷阱(转)
源地址: http://blog.csdn.net/niannian_315/article/details/24354251 今天在用BigDecimal“出现费解”现象,以前虽然知道要避免用, ...
- SQL 的坑1 除法“”不可用“”
今天工作中遇见 一问题,有5各部分,现要求5个部分各自的比例,SQL语句没有问题,后来还试了"加","减","乘","Round& ...
- Python学习---除法
python有两种除法,普通除法 a/b ,不论a,b精度 得到的都是浮点数. 4/2 = 2.0 3/5 = 0.6 floor除法,a//b , 得到一个舍弃小数位的整数结果,所以结果永远是 ...
- 【Python】一、除法问题及基本操作(逻辑与,if替代switch)及支持中文打印
1.查看版本 C:\Users\XXX>python -V Python 2.7.1 2.除法问题(不要整除) from __future__ import division tmp=0x3ec ...
- 除法取模练习(51nod 1119 & 1013 )
题目:1119 机器人走方格 V2 思路:求C(m+n-2,n-1) % 10^9 +7 (2<=m,n<= 1000000) 在求组合数时,一般都通过双重for循环c[i][ ...
- HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)
传送门:HDU 5895 Mathematician QSC 这是一篇很好的题解,我想讲的他基本都讲了http://blog.csdn.net/queuelovestack/article/detai ...
随机推荐
- [Codeforces 757E] Bash Plays with Functions (数论)
题目链接: http://codeforces.com/contest/757/problem/E?csrf_token=f6c272cce871728ac1c239c34006ae90 题目: 题解 ...
- springboot 测试类,项目使用shiro时报错UnavailableSecurityManagerException
大概的问题就是,正常运行项目是没有问题的 使用测试类是,加载不了shiro的securityManager,主要导致不是很清楚,望告知, 解决方法 @Resource org.apache.shiro ...
- 131.typename在嵌套类中的作用
#include <iostream> using namespace std; class myit { public: static int num; class itit { }; ...
- GPU学习笔记(二)
找到了一个还不错的教程http://blog.csdn.net/augusdi/article/details/12527497 今天课比较多,但是有了这个教程解决了昨天不能运行的问题.
- Maven项目:Plugin execution not covered by lifecycle configuration 解决方案
这个是eclipse中配置文件pom.xml报的错.具体错误信息: Plugin execution not covered by lifecycle configuration: org.apach ...
- realm怎样支持hashmap
realm不支持hashmap这种形式stackoverflow给出了解决方案http://stackoverflow.com/ques... class MyData extends RealmOb ...
- RMAN备份脚本
单机环境全备 export ORACLE_BASE=/oracle export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1 export ORA ...
- input的选中与否以及将input的value追加到一个数组里
html布局 <div class="mask"> //每一个弹层都有一个隐藏的input <label> <input hidden="& ...
- php文件加载、错误处理、方法函数和数组
数组运算符注意:php中,数组的元素的顺序,不是由下标(键名)决定的,而是完全由加入的顺序来决定.联合(+):将右边的数组项合并到左边数组的后面,得到一个新数组.如有重复键,则结果以左边的为准$v1 ...
- 使用U盘作为启动盘安装ubuntu系统
一.使用U盘刻录镜像 1.安装之后我们打开软件,点击文件打开,找到我们刚才进行下载的Ubuntu的ISO文件,然后点击打开,完成ISO文件的加载.接着我们插入U盘,点击UltraISO启动选项,然后 ...