UVA-725 Division
2017-03-07 21:37
1111 查看
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:
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:
#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 = %d\n",y,x,n); found=1; } } if(!found) printf("There are no solutions for %d.\n",n); } return 0; }
相关文章推荐
- uva 725 Division 简单枚举
- UVA 725:Division
- UVa725-Division
- Uva 725 Division(暴力)
- Uva725——Division
- Uva 725 Division
- uva 725 Division
- UVA 725 Division
- UVa - 725 - Division(暴力枚举)
- UVa 725 Division
- uva 725 DIVISION (暴力枚举)
- UVA 725 Division
- UVA - 725 Division (暴力枚举)
- 【例题 7-1 UVA - 725】Division
- 7-1 除法(Division,UVa 725)
- Division UVA - 725
- 除法(Division,UVa 725)
- uva725 - Division
- 除法(Division ,UVA 725)-ACM集训