除法

来源:互联网 发布:app数据接口开发 编辑:程序博客网 时间:2024/04/29 09:02

题目要求:输入正整数n,按从小到大的顺序输出所有形如abcde/fghij=n的表达式,其中a~j恰好为数字0~9的一个排列,2<=n<=79.
我的采用的是暴力枚举:
样例输入:
62
样例输出:
79546/01283=62
94736/01528=62

#include<iostream>using namespace std;intmain(void){    double n;    cin>>n;    for(int  a=0;a<=9;a++)        for(int b=0;b<=9;b++)            for(int c=0;c<=9;c++)                for(int d=0;d<=9;d++)                    for(int e=0;e<=9;e++){                    double x1=(10000*a+1000*b+100*c+10*d+e)/n;                    int y1=(10000*a+1000*b+100*c+10*d+e)/n;                    if(x1-y1<=1e-6){                        //cout<<x1<<" "<<y1<<endl;                        int f,g,h,i,j;                        f=y1%10;g=y1/10%10;h=y1/100%10;i=y1/1000%10;j=y1/10000;                        int p[10]={a,b,c,d,e,f,g,h,i,j};                        int flag=1;                        for(int x=0;x<10;x++){                            for(int y=x+1;y<10;y++){                                if(p[x]==p[y])                                    flag=0;                            }                        }                        if(flag){                            cout<<10000*p[0]+1000*p[1]+100*p[2]+10*p[3]+p[4]<<"/";                            for(int i=9;i>=5;i--)                                cout<<p[i];                                cout<<endl;                        }                    }                }    return 0;}
0 0
原创粉丝点击