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
#include <iostream>
#include <set>
#include <cstdio>
#include <map>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <queue>
#include <vector>
#include <malloc.h>
#include <algorithm>
using namespace std;
typedef long long LL;
int arr[100010];
LL sum=0;
int is_diff(int n){
set<int> temp;
int num=0;
while(n>0){
num++;
temp.insert(n%10);
n/=10;
}
if(temp.size()==num) {
return 1;
}else{
return 0;
}
}
int is_sucess(int first,int second){
if(first>=98765||second>=98765) {
// cout<<">=98765"<<endl;
return 0;
}
//每个数各不相同
if(is_diff(first)&&is_diff(second)){
//cout<<"come in"<<endl;
//需要放在一起不重复
vector<int> arr;
vector<int> cop;
for(int i=0;i<10;i++){
cop.push_back(i);
}
while(first>0){
arr.push_back(first%10);
first/=10;
}
while(second>0){
arr.push_back(second%10);
second/=10;
}
if(find(arr.begin(),arr.end(),0)==arr.end()){
arr.push_back(0);
}
sort(arr.begin(),arr.end());
if(arr==cop) return 1;
}
//cout<<"!10"<<endl;
return 0;
}
int main(){
int n;
int kase=0;
while(cin>>n&&n!=0){
int flag=0;
int maxn=0;
if(kase++) cout<<endl;
while(maxn<=98765){
if(is_sucess(maxn*n,maxn)){
flag=1;
printf("%05d / %05d = %d\n",maxn*n,maxn,n);
}
maxn++;
}
if(!flag){
cout<<"There are no solutions for "<<n<<"."<<endl;
}
}
}
//呜呜呜呜 cout<<"There are no solutions for "<<n<<"."<<endl; 别忘了后面那个点点“.”