博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Division
阅读量:6245 次
发布时间:2019-06-22

本文共 1996 字,大约阅读时间需要 6 分钟。

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 $2 \le N \le 79$. 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.

 

 

Each line of the input file consists of a valid integer 
N. An input of zero is to terminate the program.

 

 

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.

 

 

61620

 

 

There are no solutions for 61.79546 / 01283 = 6294736 / 01528 = 62

 

 暴力解决,不过要注意输出时最后一组数据不能多出空行

 

#include"iostream"#include"cstring"using namespace std;int n;int book[100]= {
0};bool judge(int c,int cc,int ccc){ memset(book,0,sizeof(book)); if(ccc==0) book[0]++; int t,f; t=c; f=0; while(t/10>0) { book[t%10]++; if(book[t%10]>1) { f=1; } t/=10; } book[t]++; if(book[t]>1) { f=1; } t=cc; while(t/10>0) { book[t%10]++; if(book[t%10]>1) { f=1; } t/=10; } book[t]++; if(book[t]>1) { f=1; } if(f) return false; return true;}void go(){ int i,flag; flag=0; for(i=1111; i<=99999; i++) { if(i*n>98765) break; if(judge(i,i*n,1)) { if((i*n)/10000==0) continue; if(i/10000==0&&judge(i,i*n,0)) { cout<
<<" / 0"<
<<" = "<
<
>n&&n) { if(x>1) cout<

 

转载于:https://www.cnblogs.com/zsyacm666666/p/4680079.html

你可能感兴趣的文章
java读取csv文件
查看>>
js判断是否为360浏览器
查看>>
京华科讯存储虚拟化技术
查看>>
Python模板库Mako的用法
查看>>
Spring整合shiro,使用jdbcTmplate操作SessionDAO
查看>>
Hibernate所鼓励的7大措施
查看>>
Python对进程Multiprocessing基础
查看>>
Shell脚本语法
查看>>
scrapy与xpath的坑
查看>>
windows 下安装tidylib
查看>>
MapReduce的那些事
查看>>
CentOS6.5环境下OpenSSL实战:自己搭建CA中心,申请,签发,吊销,导入证书,SSL 握手详解...
查看>>
关于:url伪静态
查看>>
Android开发之制作圆形头像自定义View,直接引用工具类,加快开发速度。带有源代码学习...
查看>>
申请微信公众号
查看>>
python中 __name__的使用
查看>>
(译)iPhone: 用公开API创建带小数点的数字键盘 (OS 3.0, OS 4.0)
查看>>
WSUS客户端升级使用命令行快速自动更新系统补丁包
查看>>
如何不让上网影响工作?看看作家怎么做
查看>>
MySQL 获得当前日期时间(以及时间的转换)
查看>>