码迷,mamicode.com
首页 > 其他好文 > 详细

UVA 725 Division

时间:2016-02-11 21:30:32      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

 

UVA 725 Division

标签:

原文地址:http://www.cnblogs.com/wintersong/p/5186648.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!