UVA 725 简单枚举

来源:互联网 发布:wordpress简洁cms主题 编辑:程序博客网 时间:2024/05/16 12:30
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;bool judge(int k,int m){     int a[11];     memset(a,0,sizeof(a));     if(m<=9999) a[0]++;      while(k>0)      {          a[k%10]++;          k/=10;      }      while(m>0)      {          a[m%10]++;          m/=10;      }      bool flag=true;      for(int i=0;i<10;i++)           if(a[i]!=1) flag=false;      if(flag) return true;      return false;}int main(){    int n,m=0;    while(scanf("%d",&n)&&n)    {        if(m>0) printf("\n");        m++;        bool flag=false;        for(int i=1234;;i++)        {            int k=i*n;            if(k>=100000) {                    if(!flag) printf("There are no solutions for %d.\n",n);                    break;            }            if(judge(k,i)) {                flag=true;                printf("%d / %05d = %d\n",k,i,n);            }        }    }    return 0;}

原创粉丝点击