Division
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
暴力解决,不过要注意输出时最后一组数据不能多出空行
#include"iostream"
#include"cstring"
using namespace std; int n;
int book[]= {}; bool judge(int c,int cc,int ccc)
{
memset(book,,sizeof(book));
if(ccc==) book[]++;
int t,f;
t=c;
f=;
while(t/>)
{
book[t%]++;
if(book[t%]>)
{
f=;
}
t/=;
}
book[t]++;
if(book[t]>)
{
f=;
}
t=cc;
while(t/>)
{
book[t%]++;
if(book[t%]>)
{
f=;
}
t/=;
}
book[t]++;
if(book[t]>)
{
f=;
}
if(f) return false;
return true;
} void go()
{ int i,flag;
flag=;
for(i=; i<=; i++)
{
if(i*n>) break;
if(judge(i,i*n,))
{
if((i*n)/==) continue;
if(i/==&&judge(i,i*n,))
{
cout<<i*n<<" / 0"<<i<<" = "<<n<<endl;
flag=;
}
if(judge(i,i*n,)&&i/!=)
{
cout<<i*n<<" / "<<i<<" = "<<n<<endl;
flag=;
} }
}
if(flag==) cout<<"There are no solutions for "<<n<<'.'<<endl;
} int main()
{
int x=;
while(cin>>n&&n)
{
if(x>) cout<<endl;
x++;
go(); }
return ;
}
Division的更多相关文章
- python from __future__ import division
1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...
- [LeetCode] Evaluate Division 求除法表达式的值
Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...
- 关于分工的思考 (Thoughts on Division of Labor)
Did you ever have the feeling that adding people doesn't help in software development? Did you ever ...
- POJ 3140 Contestants Division 树形DP
Contestants Division Description In the new ACM-ICPC Regional Contest, a special monitoring and su ...
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- GDC2016【全境封锁(Tom Clancy's The Division)】对为何对应Eye Tracked System,以及各种优点的演讲报告
GDC2016[全境封锁(Tom Clancy's The Division)]对为何对应Eye Tracked System,以及各种优点的演讲报告 原文 4Gamer編集部:松本隆一 http:/ ...
- Leetcode: Evaluate Division
Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...
- hdu 1034 (preprocess optimization, property of division to avoid if, decreasing order process) 分类: hdoj 2015-06-16 13:32 39人阅读 评论(0) 收藏
IMO, version 1 better than version 2, version 2 better than version 3. make some preprocess to make ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- UVALive 7327 Digit Division (模拟)
Digit Division 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/D Description We are given ...
随机推荐
- BIOS 和UEFI的区别
BIOS先要对CPU初始化,然后跳转到BIOS启动处进行POST自检,此过程如有严重错误,则电脑会用不同的报警声音提醒,接下来采用读中断的方式加载各种硬件,完成硬件初始化后进入操作系统启动过程:而UE ...
- Ubuntu 必装软件及安装教程
安装搜狗拼音输入法 因为sogou是基于fcitx的,所以先添加fcitx键盘输入法系统[系统默认是iBus].在终端中,输入命令将下载源添加至系统源(添加依赖). sudo add-apt-repo ...
- (二)python高级特性
一.切片 >>> L = ['Michael', 'Sarah', 'Tracy', 'Bob', 'Jack'] 对这种经常取指定索引范围的操作,用循环十分繁琐,因此,Python ...
- 2018年全国多校算法寒假训练营练习比赛(第五场):A题:逆序数(树状数组or归并排序)
题目描述 在一个排列中,如果一对数的前后位置与大小顺序相反,即前面的数大于后面的数,那么它们就称为一个逆序.一个排列中逆序的总数就称为这个排列的逆序数.比如一个序列为4 5 1 3 2, 那么这个序列 ...
- 数据库执行计划慢导致I/O 慢
Memory Statistics~~~~~~~~~~~~~~~~~ Begin End ------------ ------------ Host Mem (MB): 16,338.5 16,33 ...
- ActionEvent之TextField
这里我们讲这个TestField类 也就是我们的输入框,什么输入密码,用户名什么的. 一些方法: 这里说到TestField也会有事件发生,就是当你在文本框敲回车的时候. 看个例子: import j ...
- AJPFX区分this和super
this和super的区别No.区别thissuper1操作属性this.属性:表示调用本类中的属性,如果本类中的属性不存在,则从父类查找super.属性:表示调用父类中的属性2操作方法this.方法 ...
- springmvc系列一 之配置介绍(包含官网doc)
1.springmvc 官网参考地址: https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html 2 ...
- linux设置ssh连接时间
相信大家经常遇到SSH连接闲置一会就断开需要重新连接的痛苦,为了使SSH连接保持足够长的时间,我们可以使用如下两种设置 1.sshd服务配置: #vi /etc/ssh/sshd_config Cli ...
- Node.js——开放静态资源原生写法
借助了mime第三方包,根据请求地址请求的文件后缀,设置content-type