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("
");
          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
",a,f,n);
                  }          
          }
          if(!flag) printf("There are no solutions for %d.
", n);
    }
    return 0;
}


原文地址:https://www.cnblogs.com/Zeroinger/p/5493914.html