UVA 725(p182)----Division

#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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值