725:Division

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_37754288/article/details/81639462

Division

#include<bits/stdc++.h>
using namespace std;
const int maxn = 64 + 5;
int n,a[30240][6];
int num,kase = 0,cnt = 0;
int Pow(int a,int b){
    int n = 1;
    while(b--) n *= a;
    return n;
}
int judge(int n){
    int vis[10] = {0};
    for(int i = 0;i < 5;i++){
        int t = (n % Pow(10,i+1)) / Pow(10,i);
        if(vis[t]) return 0;
        a[cnt][4-i] = t;
        vis[t] = 1;
    }
    a[cnt][5] = n;
    return 1;
}
int judge2(int p){
    int vis[10] = {0};
    int cnt = 0;
    for(int i = 0;i < 5;i++) vis[a[p][i]] = 1;
    num = a[p][5]*n;
    if(num >= 100000) return 0;
    for(int i = 0;i < 5;i++){
        int t = (num % Pow(10,i+1)) / Pow(10,i);
        if(vis[t]) return 0;
        vis[t] = 1;
        cnt++;
    }
    if(cnt != 5) return 0;
    return 1;
}
int main()
{
    // freopen("data.in","r",stdin);
    // freopen("data.out","w",stdout);
    for(int i = 1234;i <= 98765;i++){
        if(judge(i)) cnt++;
    }
    while(scanf("%d",&n) && n){
        if(kase++ > 0) putchar('\n');
        int mark = 0;
        for(int i = 0;i < cnt;i++){
            if(judge2(i)){
                mark = 1;
                printf("%d / ",num);
                for(int t = 0;t < 5;t++) printf("%d",a[i][t]);
                printf(" = %d\n",n);
            }
            if(num >= 100000) break;
        }
        if(!mark) printf("There are no solutions for %d.\n",n);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37754288/article/details/81639462
今日推荐