输入正整数n,按从小到大输出所有形如abcde/fghij=n的表达式。其中a~j为0~9的一个排列,2=<n=<79.

样例输入:

62

样例输出:

79546/01283=62

94736/01528=62

(代码有些累赘。。。)

#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int a,b,c,d,e;
        for(a=0;a<=9;a++)
            for(b=0;b<=9;b++)
                for(c=0;c<=9;c++)
                    for(d=0;d<=9;d++)
                        for(e=0;e<=9;e++)
                        {
                            int x=a*10000+b*1000+c*100+d*10+e;
                            if(!(x%n)){
                            int y=x/n;
                            int f=y/10000,g=y/1000%10,h=y/100%10,i=y/10%10,j=y%10;
                            int buf[10];
                            buf[0]=a,buf[1]=b,buf[2]=c,buf[3]=d,
                            buf[4]=e,buf[5]=f,buf[6]=g,buf[7]=h,
                            buf[8]=i,buf[9]=j;
                            for(int k=0;k<9;k++){
                                for(int t=k+1;t<10;t++)if(!(buf[k]-buf[t]))break;
                                if(t!=10)break;
                            }
                            if(k==9)
                                printf("%d%d%d%d%d/%d%d%d%d%d=%d\n",a,b,c,d,e,f,g,h,i,j,n);
                            }
                        }
    }
    return 0;
}

 

相关文章:

  • 2022-02-04
  • 2021-04-13
  • 2021-12-06
  • 2022-01-27
  • 2022-03-10
  • 2021-06-28
  • 2022-02-20
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2021-11-04
  • 2022-02-14
  • 2022-02-02
  • 2021-12-26
相关资源
相似解决方案