題目要求:輸入正整數(shù)n,按從小到大的順序輸出所有形如abcde/fghij=n的表達式,其中a~j恰好為數(shù)字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;}新聞熱點
疑難解答