您的位置:首页 > 其它

UVA 725 - Division

2015-07-29 08:58 495 查看
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666

题       意:给你一个数n,找出有1----9组成的两个五位数满足x/y==n。

思       路:直接暴力即可。即直接在(1000,100000)内枚举y。

代码如下:

#include <iostream>
using namespace std;
#include <string.h>
#include <stdio.h>
#include <queue>
#include <algorithm>
int a[10];
int sum( int x, int y )
{
if( y > 98765 ) return 0;
memset(a,0,sizeof(a));
if(x<10000)
a[0]=1;
while( x )
{
a[x%10]++;
x/=10;
}
while(y)
{
a[y%10]++;
y/=10;
}
for( int i = 0; i < 10; i ++ )
{
if(a[i]>1) return 0;
if(a[i]==0) return 0;
}
return 1;
}
int main()
{
int n,ans=0;
while( scanf ( "%d", &n ) != EOF )
{
if( n == 0 ) break;
if(ans++) printf("\n");
int  f = 1;
for( int i = 1234; i < 100000; i ++ )
if( sum( i, i*n ) )
{
f=0;
printf("%05d / %05d = %d\n",i*n,i,n);
}
if( f ) printf("There are no solutions for %d.\n",n);
}
return 0;
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  暴力