UVA - 725 Division

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    bool first = true;
    while(cin >> n && n){
        if(first){
            first = false;
        }else
            printf("\n");
        bool ok = false;
        for(int i = 1234; i <= 98765; i++){ //0作为x的前导0,因此全部数为1-9
            int x = i, y = x*n;
            if(y / 10000 < 1 || y / 10000 > 9){
                continue;
            }
            set<int>s;
            while(x){
                s.insert(x % 10);
                x /= 10;
            }
            while(y){
                s.insert(y % 10);
                y /= 10;
            }
            if(i < 10000 && s.size() == 9 && *s.begin() != 0){
                ok = true;
                printf("%d / 0%d = %d\n", i*n, i, n);
            }
            if(i > 10000 && s.size() == 10){
                ok = true;
                printf("%d / %d = %d\n", i*n, i, n);
            }
        }
        if(!ok){
            printf("There are no solutions for %d.\n", n);
        }
        
    }
    return 0;
}

 

posted on 2019-02-27 20:59  nbsanshi  阅读(108)  评论(0编辑  收藏  举报

导航