UVA 725 Division

#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
#include<cstdio>
using namespace std;
int main(){
   int n,ss=0;
   int hh[10];
   bool flag=false,esca=false;
   while(cin>>n){
         if(n==0) break;
        ss++;
        if(ss!=1)cout<<endl;
        flag=false;
        esca=false;
   
    int a,num,b,s;
    for(int i=10000;i<99999;i++){
             esca=false;
        a=i;num=0;
        memset(hh,0,sizeof(hh));
        while(a){
            if(hh[a%10]==0){
                hh[a%10]=1;
                a/=10;
                num++;
            }else
            break;

        }
        if(num==5&&i%n==0) {
            b=i/n;
            s=b;
            num=0;
            while(b){
                if(hh[b%10]==0){
                    hh[b%10]=1;
                    b/=10;
                    num++;
                }else {
                    esca=true;
                    break;
                }
            }

            if(num==4&&hh[0]==0&&esca==false) {cout<<i<<" / 0"<<s<<" = "<<n<<endl;flag=true;}
             if(num==5) {cout<<i<<" / "<<s<<" = "<<n<<endl;flag=true;}
        }


    }
     if(flag==false)
               cout<<"There are no solutions for "<<n<<"."<<endl;

   }

    return 0;
}

 

posted @ 2016-02-11 20:47  咸咸的告别  阅读(166)  评论(0编辑  收藏  举报