我是靠谱客的博主 标致航空,这篇文章主要介绍UVA-725 Division,现在分享给大家,希望可以做个参考。

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 2 ≤ N ≤ 79. 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

分析:暴力枚举。技巧:除数从1234开始枚举,被除数为除数乘以n,在判断是否用到0~9各一次。

Source:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<stdio.h> #include<string.h> int n,found; int num[10]={0}; int main() { int x,y,a,b; int i,t=0; while(scanf("%d",&n)!=EOF&&n!=0) { if(t++) printf("n"); found=0; for(x=1234;x<=86420;x++) { memset(num,0,sizeof(num)); y=x*n; if(y>98765) break; a=x;b=y; for(i=1;i<=5;i++) { num[a%10]++; num[b%10]++; a/=10; b/=10; } for(i=0;i<10;i++) { if(num[i]==0||num[i]>1) break; } if(i==10) { printf("%05d / %05d = %dn",y,x,n); found=1; } } if(!found) printf("There are no solutions for %d.n",n); } return 0; }

最后

以上就是标致航空最近收集整理的关于UVA-725 Division的全部内容,更多相关UVA-725内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部