HALF<水题>

来源:互联网 发布:乐视1s移动数据开关 编辑:程序博客网 时间:2024/04/30 03:54

题意:

找出n/d=0.5的所有数。输入:test,x(代表n的位数,1<=x<=4).并且n和d的每一个位数不能有重复,也不能是0。输入:11输出:the form 1/2 = 0.5.the form 2/4 = 0.5.the form 3/6 = 0.5.the form 4/8 = 0.5.the form 6/12 = 0.5.the form 7/14 = 0.5.the form 8/16 = 0.5.the form 9/18 = 0.5.
#include<cstdio>#include<cmath>using namespace std;int main (){    int a[10];    int t;scanf("%d",&t);    while(t--){        int n;scanf("%d",&n);        int mi=pow(10,n-1);        int ma=pow(10,n)-1;        for(int k=mi;k<=ma;k++){            for(int i=0;i<10;i++) a[i]=0;            int A=k;            int B=2*A;            while(A) a[A%10]++ , A/=10;            while(B) a[B%10]++ , B/=10;            int flag=1;            for(int i=0;i<10;i++) if(a[0]||a[i]>1) flag=0;            if(flag) printf("the form %d/%d = 0.5.\n",k,2*k);        }    }    return 0;}
0 0
原创粉丝点击