uva725(除法)
2015-07-27 19:58
302 查看
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
Sample Output
Miguel Revilla
2000-08-31
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
相关文章推荐
- Oracle OCP笔记(27)RMAN备份
- 如何调用另一个python文件中的代码
- 【转】java中的TreeMap与TreeSet关系及实现(红黑树)
- hdu 1870 愚人节的礼物
- [python]小技巧集锦
- 面试题22_栈的压入和弹出序列
- poj 3181 网络流,建图。
- Android中的5种数据存储方式之——文件存储数据
- legacy boot与uefi boot
- VirtualBox利用启动优盘安装虚拟机
- 《深入了解Android:Wi-Fi、NFC和GPS音量》勘误表
- codeforces 559C Gerald and Giant Chess (dp+乘法逆元)
- 【飞天奔月出品】memcached四大注意事项(key长度,空格限制,最大item)
- android的事物
- shell脚本 如何切换当前目录
- 【HTTP】简单的HTTP下载网页流程(HTTPClient4.3)
- LeetCode 208. Implement Trie (Prefix Tree)
- 今天要用到可折叠的tableview 折腾了半天
- poj 2485 Highways
- HDU 1671 Phone List (Trie·数组实现)