UVa 725

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=666

题目大意是输入一个数n,按照从大到小的顺序输出所有如abcde/fighi=n的表达式,而a----j是0---9的一个全排列,我们只需要枚举fighi即可,不到10000个数,从1234开始。代码如下:

/* **********************************************
Auther: zyq_zhang
Created Time: 2015/9/1 19:51:13
File Name   : UVa725.cpp
*********************************************** */
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
char b[99];
int main()
{    
    int n,k=0;
    while(scanf("%d",&n)!=EOF&&n!=0)
    {  
          int a,f;
          bool flag=false;
          if(k++) printf("\n");
          for(f=1234;f<=99999;f++)
          {       
                  bool ok=true;
                  a=f*n;
                  sprintf(b,"%05d%05d",a,f);
                  if(strlen(b)>10) break;
                  sort(b,b+10);
                  for(int i=0;i<10;i++)
                  {
                          if(b[i]!='0'+i) ok=false;
                  }
                  if(ok)
                  {
                          flag=true;
                          printf("%05d / %05d = %d\n",a,f,n);
                  }          
          }
          if(!flag) printf("There are no solutions for %d.\n", n);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值