Division,Uva725
来源:互联网 发布:mac os 最快稳定的版本 编辑:程序博客网 时间:2024/06/07 02:26
暴力求解Description
Download as PDF
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
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
解题思路:枚举其中的分母或分子,这样能提高效率,在判断数字是否在0~9之间,用数组标法,做过好多题都是用数组标记法来判断该数字是否出现过,
还有就是注意细节。
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int N,f=0;int meiju(int a,long long b);int main(){ int k=0; while(cin>>N&&N!=0) { if(k!=0) //细节所在, cout<<endl; k++; for(int i=10000;i<98765;i++) { if((i/N)*N==i) { if(meiju(i,i/N)) { printf("%05d / %05d = %d\n",i,i/N,N); f=1; } } } if(f==0) printf("There are no solutions for %d.\n",N); f=0; } return 0;}int meiju(int a,long long b){ int a1,b1; int A[10]={0}; a1=a,b1=b; while(a1) { if(A[a1%10]) //标记分母中出现的数字。 return 0; else A[a1%10]=1; a1=a1/10; } while(b1) { if(A[b1%10]) //标记分子中出现的数字。 return 0; else A[b1%10]=1; b1=b1/10; } for(int i=1;i<10;i++) if(A[i]!=1)return 0; return 1;}
- 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 - 725 - Division
- Uva725——Division
- UVa725 Division(暴力)
- UVA725 UVALive5362 Division
- UVA725 Division【暴力枚举】
- 图片拉伸
- 算法
- 初探HTML 5 Canvas元素
- 安卓系统物理按键和虚拟按键同时存在
- Dubbo官网
- Division,Uva725
- jQuery之选择器
- Remove Nth Node From End of List
- POJ2349,ZOJ1914,Arctic Network
- JSVM介绍以及如何配出各种可分级
- Mysql(用户相关命令)查看所有用户及权限、删除创建用户等命令
- java+poi读取和存储excel表格内容
- UltraEdit 配置 shell 语法高亮
- 【Unity3D游戏开发】之Sprite Packer使用方法 (九)