UVA725 - 725 - Division
来源:互联网 发布:台式电脑连接不上网络 编辑:程序博客网 时间:2024/06/03 21:43
Division
Time limit: 3.000 seconds
Write a program that finds and displays all pairs of 5-digit numbers that between them use the digits 0through 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 forN.". Separate the output for two different values of N by a blank line.
Sample Input
61620Sample Output
There are no solutions for 61.79546 / 01283 = 6294736 / 01528 = 62一个简单的枚举题目,枚举0~9的所有排列时没有必要的!而且也是不可实现的!只需枚举题目中的 fghij 就可以算出 abcde, 然后再判断所有数字都不相同即可!#include <stdio.h>#include <iostream>#include <string.h>#include <algorithm>using namespace std;int solve(int a, int b){ int bj[10], num[10], aa = a, bb = b; /// bj数组用来记录每一位出现的次数,num数组用来记录是否出现 memset(bj,0,sizeof(bj)); memset(num,0,sizeof(num)); if(b > 98765) return 0; if(a < 10000) {num[0] = 1;bj[0] = 1;}///小于10000,存在一个前导0 while(a) { num[a%10] = 1; bj[aa%10]++; a /= 10; aa /= 10; } while(b) { num[b%10] = 1; bj[bb%10]++; b /= 10; bb /= 10; } int sum = 0; for(int j = 0; j < 10; j++) if(bj[j] == 1) sum += num[j]; return (sum == 10);}int main(){ int n, t = 0; while(scanf("%d",&n)&&n!=0) { if(t++) printf("\n"); int cnt = 0; for(int i = 1234; i < 100000; i++) { if(solve(i,i*n)) { printf("%05d / %05d = %d\n",i*n,i,n); cnt++; } } if(!cnt) printf("There are no solutions for %d.\n",n); } return 0;}
0 0
- UVA725 - 725 - Division
- uva725-Division
- UVa725 Division
- UVa725 - Division
- uva725 Division
- Division,Uva725
- UVA725-Division
- uva725 - Division
- uva725 Division
- UVa725-Division
- UVA725 - Division
- UVA725 Division
- Uva725 Division
- UVA725 Division【枚举】
- Uva725——Division
- UVa725 Division(暴力)
- UVA725 UVALive5362 Division
- UVA725 Division【暴力枚举】
- POJ 3026 (BFS+最小生成树)
- java内存管理的8个小技巧
- android studio中文件内容查找相当于Eclipse中Ctrl+H & 查找项目中所有中文
- 机器学习的数学基础(1)--Dirichlet分布
- 工作日志4
- UVA725 - 725 - Division
- hdu 2295 &&hdu 5046
- 用Unreal开发一个简单的MC Demo (1)
- ubuntu环境安装lamp-apt-get安装
- 敏捷的軟體開發流程(CMMI)
- 堆的调整
- sql优化
- [LeetCode][Java] Spiral Matrix II
- sizeof 使用