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的更多相关文章

  1. python from __future__ import division

    1.在python2 中导入未来的支持的语言特征中division(精确除法),即from __future__ import division ,当我们在程序中没有导入该特征时,"/&qu ...

  2. [LeetCode] Evaluate Division 求除法表达式的值

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

  3. 关于分工的思考 (Thoughts on Division of Labor)

    Did you ever have the feeling that adding people doesn't help in software development? Did you ever ...

  4. POJ 3140 Contestants Division 树形DP

    Contestants Division   Description In the new ACM-ICPC Regional Contest, a special monitoring and su ...

  5. 暴力枚举 UVA 725 Division

    题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...

  6. GDC2016【全境封锁(Tom Clancy's The Division)】对为何对应Eye Tracked System,以及各种优点的演讲报告

    GDC2016[全境封锁(Tom Clancy's The Division)]对为何对应Eye Tracked System,以及各种优点的演讲报告 原文 4Gamer編集部:松本隆一 http:/ ...

  7. Leetcode: Evaluate Division

    Equations are given in the format A / B = k, where A and B are variables represented as strings, and ...

  8. 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 ...

  9. uva 725 Division(暴力模拟)

    Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...

  10. UVALive 7327 Digit Division (模拟)

    Digit Division 题目链接: http://acm.hust.edu.cn/vjudge/contest/127407#problem/D Description We are given ...

随机推荐

  1. 《Windows核心编程系列》十二谈谈Windows内存体系结构

    Windows内存体系结构 理解Windows内存体系结构是每一个励志成为优秀的Windows程序员所必须的. 进程虚拟地址空间 每个进程都有自己的虚拟地址空间.对于32位操作系统来说,它的地址空间是 ...

  2. Application,Service,Activity 三者的Context的应用场景

    Application 的 context 不是万能的,所以也不能随便乱用,对于有些地方则必须使用 Activity 的 Context, 对于Application,Service,Activity ...

  3. 转】RDD与DataFrame的转换

    原博文出自于: http://www.cnblogs.com/namhwik/p/5967910.html RDD与DataFrame转换1. 通过反射的方式来推断RDD元素中的元数据.因为RDD本身 ...

  4. AJPFX:如何保证对象唯一性呢?

    思想: 1,不让其他程序创建该类对象. 2,在本类中创建一个本类对象. 3,对外提供方法,让其他程序获取这个对象. 步骤: 1,因为创建对象都需要构造函数初始化,只要将本类中的构造函数私有化,其他程序 ...

  5. Maximum Subsequence Sum 最大子序列和的进击之路

    本文解决最大子序列和问题,有两个题目组成,第二个题目比第一个要求多一些(其实就是要求输出子序列首尾元素). 01-复杂度1 最大子列和问题   (20分) 给定KK个整数组成的序列{ N1​​, N2 ...

  6. window下phpstudy开启redis扩展

    注:一定要注意自己PHP的版本结构是64还是32位的!其次查看PHP Extension Build是NTS or TS! 1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本(特 ...

  7. Node.js——express

    res.send(),比原生的 res.end() 强大,原生只支持字符串和Buffer对象,而且需要自己加响应报文头,send支持字符串.Buffer.Json对象.数组,而且自动加响应报文头 ap ...

  8. 原生jsonp跨域

    <script> // jsonp跨域原生写法 var script = document.createElement('script'); script.src = 'http://19 ...

  9. jpa,querydsl

    [TOC] # jpa ## 生成通用模板 实现自定义方法有两种方法: 1. 根据衍生规则进行实现,此种情况简单:查询方法衍生规则 http://docs.spring.io/spring-data/ ...

  10. PHP运算符考察点

    PHP运算符优先级 运算符优先级指定了两个表达式绑定得有多"紧密".例如,表达式 1 + 5 * 3 的结果是 16 而不是 18 是因为乘号(*)的优先级比加号(+)高.必要时可 ...