UVA 725 – 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
Miguel Revilla
2000-08-31 从1234到99999枚举一遍就行了。。
#include<stdio.h>
int number[];
int check(int a, int b){
if(a > )return ;
for(int i=;i< ;i++){
number[i] = ;
}
if(b<)number[] = ;
while (a){
number[a%] = ;
a /= ;
}
while (b){
number[b%] = ;
b /= ;
}
int sum = ;
for (int i=; i<; i++)
sum += number[i];
return sum == ;
}
int main() {
int ans, cnt = ;
while (scanf("%d", &ans) == , ans) {
if (cnt++) printf("\n");
int flag = ;
for (int i = ;i<;i++){
if (check(i*ans,i)){
printf("%05d / %05d = %d\n", i * ans, i, ans);
flag = ;
}
}
if (!flag) {
printf("There are no solutions for %d.\n",ans);
}
}
return ;
}
UVA 725 – Division的更多相关文章
- 暴力枚举 UVA 725 Division
题目传送门 /* 暴力:对于每一个数都判断,是否数字全都使用过一遍 */ #include <cstdio> #include <iostream> #include < ...
- uva 725 Division(除法)暴力法!
uva 725 Division(除法) A - 暴力求解 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & ...
- UVA.725 Division (暴力)
UVA.725 Division (暴力) 题意分析 找出abcdefghij分别是0-9(不得有重复),使得式子abcde/fghij = n. 如果分别枚举每个数字,就会有10^10,肯定爆炸,由 ...
- uva 725 Division(暴力模拟)
Division 紫书入门级别的暴力,可我还是写了好长时间 = = [题目链接]uva 725 [题目类型]化简暴力 &题解: 首先要看懂题意,他的意思也就是0~9都只出现一遍,在这2个5位数 ...
- Uva 725 Division
0.不要傻傻的用递归去构造出一个五位数来,直接for循环最小到最大就好,可以稍微剪枝一丢丢,因为最小的数是01234 从1234开始,因为倍数n最小为2 而分子是一个最多五位数,所以分母应该小于五万. ...
- uva 725 division(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABVMAAAOHCAIAAAClwESxAAAgAElEQVR4nOydybGturJFcQEPfgQu4A
- uva 725 DIVISION (暴力枚举)
我的56MS #include <cstdio> #include <iostream> #include <string> #include <cstrin ...
- UVA 725 division【暴力枚举】
[题意]:输入正整数n,用0~9这10个数字不重复组成两个五位数abcde和fghij,使得abcde/fghij的商为n,按顺序输出所有结果.如果没有找到则输出“There are no solut ...
- UVa 725 Division (枚举)
题意 : 输入正整数n,按从小到大的顺序输出所有形如abcde/fghij = n的表达式,其中a-j恰好为数字0-9的一个排列(可以有前导0),2≤n≤79. 分析 : 最暴力的方法莫过于采用数组存 ...
随机推荐
- Swipe JS滑动插件
Swipe JS 是一个轻量级的移动滑动组件,支持 1:1 的触摸移动,阻力以及防滑性能都不错,可以让移动web应用展现更多的内容,能解决我们对于移动Web对滑动的需求. 官网:http://www. ...
- 如何设置ssh安全只允许用户从指定的IP登陆
原文链接: 如何设置ssh安全只允许用户从指定的IP登陆 由于开发上传文件需要 在服务器上开启 允许用户名和密码ssh登录.这样不太安全.百度后参考文章现在ssh用户名和密码登录的ip. 登录服务 ...
- 鸟哥私房菜--第1章 Linux 是什么
[只做搬运工,在搬运的时候窃看其中乐趣.] 历史渊源 Linus Torvalds(请记住这个名字)当年(1991)在写Linux的时候,初衷是针对386型机器的,当时只是一套裸露的操作系统并不包含任 ...
- Spring如何管理Session【转贴】
在使用Spring进行系统开发的时候,数据库连接一般都是配置在Spring的配置文件中,并且由Spring来管理的.在利用Spring + Hibernate进行开发时也是如此.下面是一个简单的Spr ...
- php 解析url 和parse_url使用
通过url进行传值,是php中一个传值的重要手段.所以我们要经常对url里面所带的参数进行解析,如果我们知道了url传递参数名称,例如 /index.php?name=tank&sex=1#t ...
- JSU省赛队员选拔赛个人赛1(Coin Change、Fibbonacci Number、Max Num、单词数、无限的路、叠筐)
JSU省赛队员选拔赛个人赛1 一.题目概述: A.Coin Change(暴力求解.动态规划) B.Fibbonacci Number(递推求解) C.Max Num(排序.比较) D.单词数 ...
- 第三届蓝桥杯 c/c++真题
第三届蓝桥杯真题 c/c++ 以下题目我自己也并不是所有的题目都是一次性就能做对或是有结题思路的.有些题目也是经过查证网上相关的资料或是参考了别人的代码和解题思路才做出来的.总的来看,这份题目考了很多 ...
- python中eval, exec, execfile,和compile [转载]
eval(str [,globals [,locals ]])函数将字符串str当成有效Python表达式来求值,并返回计算结果. 同样地, exec语句将字符串str当成有效Python代码来执行. ...
- debian安装jdk8
1.官方下载java想安装的JAVA版本: http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.比如说,常安装的J ...
- 基于visual Studio2013解决C语言竞赛题之0710排序函数
题目