uva725 Division(枚举)

题目给出一个n ,求所有a/b=n 要求ab中数字不一样  枚举分母或者分分子就行了

注意输出格式

题目:

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
le N le 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

代码:

 1 #include <iostream>
 2 #include <iomanip>
 3 #include <memory.h>
 4 #include <cstdio>
 5 using namespace std;
 6 
 7 int flag =0;
 8 int n;
 9 //int B[5];
10 int judge(int i,long long k)
11 {
12     int vis[10];
13     memset(vis,0,sizeof(vis));
14 
15     int ti=i,tk=k;
16     while(ti)
17     {
18         if(vis[ti%10])
19            return 0;
20         else
21            vis[ti%10]=1;
22 
23         ti/=10;
24     }
25     while(tk)
26     {
27         if(vis[tk%10])return 0;
28         else vis[tk%10]=1;
29 
30         tk/=10;
31 
32     }
33     for(int g=1;g<10;g++)
34         if(!vis[g]){return 0;}
35 
36     cout<<setw(5)<<setfill('0')<<i<<" / "<<setw(5)<<setfill('0')<<k<<" = "<<n<<endl;
37 
38     return 1;
39 }
40 
41 int main()
42 {
43     freopen("out","w",stdout);
44     int tst=0;
45 
46     while(cin>>n)
47     {
48         if(n==0)break;
49      if(tst>1)cout<<endl;
50       for(int i=10000;i<=99999;i++)
51       {
52           if(int(i/n)*n==i)
53           {
54               if(judge(i,i/n))
55               {
56                   flag = 1;
57               }
58           }
59       }
60        if(!flag)
61        {
62                 cout<<"There are no solutions for "<<n<<"."<<endl;
63        }
64        flag =0;
65     if(!tst){cout<<endl;}
66     tst++;
67     }
68 
69     return 0;
70 }
原文地址:https://www.cnblogs.com/doubleshik/p/3491444.html