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. pyinstaller打包.py程序为.exe操作指南

    pyinstaller打包.py程序为.exe操作指南 20190526内容纲要: 1.pyinstaller安装 2.程序封装 3.可执行程序 0 前言 今天第一次试试将一个py程序封装成一个.ex ...

  2. 【BZOJ3514】Codechef MARCH14 GERALD07加强版(LCT_主席树)

    题目: BZOJ3514 分析: 看到这题真的是一脸懵逼无从下手,只好膜题解.看到「森林的联通块数 = 点数 - 边数」这一句话就立刻什么都会了 QAQ . 这题最重要的就是意识到上面那个式子(正确性 ...

  3. QT5之2D绘图-绘制路径

    在绘制一个复杂的图形的时候,如果你需要重复绘制一个这样的图形,就可以使用到QPainterPath类,然后使用QPainter::drawPath()来进行绘制. QPainterPath类为绘制操作 ...

  4. python优缺点分析及python种类

    Python的缺点: 相较于其它类型的语言可能运行速度上会略差.C语言的运行性能速度上最好,因为C最接近计算机底层. Python的优点: 大数据处理,有专门的功能模块,比较方便. Linux自带Py ...

  5. [转]C# 邮箱验证激活

    原文链接 /// <summary> /// 发送邮件 发送激活码 /// </summary> /// <param name="address"& ...

  6. 转 Docker 组件如何协作?- 每天5分钟玩转容器技术(8)

    http://www.cnblogs.com/CloudMan6/p/6774519.html 记得我们运行的第一个容器吗?现在通过它来体会一下 Docker 各个组件是如何协作的. 容器启动过程如下 ...

  7. solr 6.0 没有schema.xml未自动创建schema文件

    solr 6.0 没有schema.xml未自动创建schema文件 摘要:在之前的Solr版本中(Solr5之前),在创建core的时候,Solr会自动创建好schema.xml,但是在之后的版本中 ...

  8. Vmware workstation12里如何正确快速安装可视化IDS系统Security Onion(图文详解)

    不多说,直接上干货! 首先,大家要明确: 问:安全洋葱能阻止入侵吗? 答:这一点,和OSSIM一样,不能阻止入侵. Security Onion基于Ubuntu,包含了入侵检测.网络安全监控.日志管理 ...

  9. sdut2355Binary Search Heap Construction

    链接 捣鼓了一下午..按堆建树 写完交 返回TLE..数据不大 感觉不会超了 无奈拿了数据来看什么奇葩数据会超 发现数据跟我输出不一样 看了好久才明白理解错题意了 给出的字符串有两个标签 按前一个来建 ...

  10. Java8-Lomda表达式

    Lomda表达式 /** * All rights Reserved, Designed By www.bingo.com * @Title TestLamda.java * @author yang ...