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. hdu---------3189-------------------

    水体一个,但是这种做题的方法值得发扬光大............ Just Do It Time Limit: / MS (Java/Others) Memory Limit: / K (Java/O ...

  2. Dock

    搭建本地 Registry - 每天5分钟玩转 Docker 容器技术(20) 小结: dock 版本号 分为 3位,比如1.1.2 就分为1, 1.1,1.1,2 这个几个版本 这种 tag 方案使 ...

  3. outlook 通讯录分类--2017年1月16日--对联系人分类管理

    outlook功能多,复杂,导致打开界面就晕,通讯录分类 问:在Outlook 中,随着联系人数量的增多,亲朋好友.同事.客户的信息混杂在一起,每次发邮件都要用很长时间才能从联系人列表中找到需要的人. ...

  4. call方法的使用bug--参数undefined

    call/apply是函数原型定义的方法(Function.prorotype),在使用时要注意第一个形参(args[0]),一定是指向函数所要挂载的上下文对象--context,若对象非必须,则要将 ...

  5. Jenkins .NET项目持续集成配置

    基本步骤 1. 安装并配置MSBUILD 在系统管理->插件管理->添加MSBuild插件 在系统管理->系统设置->找到MSBuild配置部分,配置不同的MSbuild版本 ...

  6. 【PostgreSQL-9.6.3】Red Hat 4.4.7下的安装

    1. 下载源码包https://www.postgresql.org/ftp/source/v9.6.1/ 2. 上传到/opt目录下 3. 创建postgres用户及dba组,并修改压缩包的属主属组 ...

  7. Farseer.net轻量级ORM开源框架 V1.x 入门篇:新版本说明

    导航 目   录:Farseer.net轻量级ORM开源框架 目录 上一篇:没有了 下一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:数据库配置 前言 V1.x版本终于到来了.本次 ...

  8. Fragment中获取Activity的Context (转)

    Fragment中获取Activity的Context时只需要this.getActivity()即可.     而不是许多人说的this.getActivity().getApplicationCo ...

  9. CREATE CAST - 定义一个用户定义的转换

    SYNOPSIS CREATE CAST (sourcetype AS targettype) WITH FUNCTION funcname (argtype) [ AS ASSIGNMENT | A ...

  10. $("[lay-id='"+this.id+"']")

    $("[lay-id='"+this.id+"']") $("[lay-id='"+this.id+"'] .layui-tabl ...