#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
int n,cc[10],dd[10],cas=0;
LL temp1,temp2;
bool flag;
bool check(LL a,LL b)
{
int top1=0,top2=0;
memset(cc,0,sizeof(cc));
memset(dd,0,sizeof(dd));
while(a>0)
{
top1++;
cc[top1]=a%10;
a/=10;
}
while(top1<5)
{
top1++;
cc[top1]=0;
}
while(b>0)
{
top2++;
dd[top2]=b%10;
b/=10;
}
while(top2<5)
{
top2++;
dd[top2]=0;
}
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j++)
if((cc[i]==dd[j])||((cc[i]==cc[j])&&(i!=j))||((dd[i]==dd[j])&&(i!=j))) return 0;
return 1;
}
int main()
{
// freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
while(scanf("%d",&n)==1&&n)
{
flag=0;cas++;
if(cas!=1) puts("");
for(int a=0;a<=9;a++){
for(int b=0;b<=9;b++)
if(a!=b)
for(int c=0;c<=9;c++)
if(a!=c&&b!=c)
for(int d=0;d<=9;d++)
if(a!=d&&b!=d&&c!=d)
for(int e=0;e<=9;e++)
if(a!=e&&b!=e&&c!=e&&d!=e)
{
temp1=e+d*10+c*100+b*1000+a*10000;
temp2=temp1*n;
if(temp1>99999||temp2>99999) break;
if(check(temp1,temp2))
{
flag=1;
for(int i=5;i>=1;i--)
cout<<dd[i];
cout<<" / ";
for(int i=5;i>=1;i--)
cout<<cc[i];
cout<<" = ";
cout<<n<<endl;
}
}
}
if(!flag) cout<<"There are no solutions for "<<n<<"."<<endl;
}
return 0;
}
题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666
UVA 725(p182)----Division
最新推荐文章于 2023-03-22 20:32:32 发布