uva 725 division(水题)——yhx
1 #include<cstdio> 2 #include<cmath> 3 #include<cstring> 4 bool b; 5 bool ok(int x,int y) 6 { 7 int p,q,i; 8 if (x<10000) return 0; 9 bool bb[15]={0}; 10 for (i=1;i<=5;i++) 11 { 12 p=x%10; 13 if (bb[p]) return 0; 14 bb[p]=1; 15 x/=10; 16 } 17 for (i=1;i<=5;i++) 18 { 19 p=y%10; 20 if (bb[p]) return 0; 21 bb[p]=1; 22 y/=10; 23 } 24 return 1; 25 } 26 int main() 27 { 28 int i,j,k,n,x,y; 29 bool bbbb=0; 30 while (scanf("%d",&n)&&n) 31 { 32 if (bbbb) printf("\n"); 33 bbbb=1; 34 b=0; 35 for (y=1234;y<=98765;y++) 36 { 37 x=y*n; 38 if (x>=100000) break; 39 if (ok(x,y)) 40 { 41 printf("%d / ",x); 42 if (y<10000) printf("0"); 43 printf("%d = %d\n",y,n); 44 b=1; 45 } 46 } 47 if (!b) printf("There are no solutions for %d.\n",n); 48 } 49 }
枚举分母,验证分子。当分子超过五位时停止。注意前导0的处理。