【暴力】abcde/fghij

UVA725 Division

#include
#include
#include
#include
using namespace std;
int main()
{
    int n,cnt=0;
    while(cin>>n&&n){
        if(cnt)printf("\n");
        else cnt++;
        char s[20];
        int ok=0;
        for(int i=1234;i<50000;i++){
            if(i*n>98765)break;
            if(i<10000)sprintf(s,"%d%d%d",0,i,i*n);
            else sprintf(s,"%d%d",i,i*n);
            sort(s,s+10);
            if(strcmp(s,"0123456789")==0){
                printf("%d / %05d = %d\n",i*n,i,n);
                ok=1;
            }
        }
        if(!ok)printf("There are no solutions for %d.\n",n);
    }
}

 

你可能感兴趣的:(【暴力】)