UVA725

UVA725
题意:输入整数n,按从小到大顺序输出所有形如abcde/fghij=n的表达式,其中aj恰好为09的一个排列(可以有前导0),2<=n<=79

#include<bits/stdc++.h>
using namespace std;
bool s[10];
bool solve(int k, int n){
    int t;
    t = k;
    if(k * n > 100000 || k * n < 10000)
        return false;
    memset(s, false, sizeof(s));
    if(k < 10000)
        s[0] = true;
    while(t){
        if(s[t % 10])
            return false;
        s[t % 10] = true;
        t /= 10;
    }
    t = k * n;
    while(t){
        if(s[t % 10])
            return false;
        s[t % 10] = true;
        t /= 10;
    }
    return true;

}
int main(){
    #ifdef ONLINE_JUDGE
    #else
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE
    int n, cnt;
    bool flag = false;
    while(scanf("%d", &n) && n){
        cnt = 0;
        if(!flag)
            flag = true;
        else
            printf("\n");
        memset(s, false, sizeof(s));
        for(int i = 1000; i < 100000; i++){
            if(solve(i, n)){
                cnt++;
                printf("%d / %05d = %d\n", i * n, i, n);
            }
        }
        if(!cnt)
            printf("There are no solutions for %d.\n", n);
    }
    return 0;
}

posted on 2019-01-04 16:25  坤sir  阅读(110)  评论(0编辑  收藏  举报

导航