【题解】UVa P725 【Division】

输出很烦,

只要枚举fghij就可以算出abcde,然后判断是否所有数字都不相同即可。

#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    int iDenominator, iNumerator, iAns;
    register int i, iTemp;
    bool arrNums[10] = { 0 };
    bool IsFound=false, IsNoOutput=true;
    while (cin >> iAns && iAns!=0){
        if (IsNoOutput)
            IsNoOutput = false;
        else
            cout<<endl;
        for (iDenominator = 1000; iDenominator <= 50000; ++iDenominator){
            iNumerator = iAns*iDenominator;
            if (iNumerator > 99999){
                break;
            }
            if (iNumerator < 10000){
                continue;
            }
            if (iDenominator < 10000){
                arrNums[0] = true;
            }
            iTemp = iDenominator;
            while (iTemp != 0){
                arrNums[iTemp % 10] = true;
                iTemp /= 10;
            }
            iTemp = iNumerator;
            while (iTemp != 0){
                arrNums[iTemp % 10] = true;
                iTemp /= 10;
            }
            if (count(arrNums, arrNums + 10, false) == 0){
                cout << iNumerator << " /" << (iDenominator < 10000 ? " 0" : " ") << iDenominator << " = " << iAns<<endl;
                IsFound = true;
            }
            for (i = 0; i <= 9; ++i){
                arrNums[i] = false;
            }
        }
        if (!IsFound){
            cout << "There are no solutions for " << iAns << ".\n";
        }
        IsFound = false;
    }
    return 0;
}