有时候,我们会用暴力枚举解决问题,比如 ABCDE*X=EDCBA,则,我们可以把所有情况全列出来,再判断。上代码:
#include<iostream>
using namespace std;
int main(){
for(int a=1;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=1;e<=9;e++){
for(int x=2;x<=9;x++){
if(a!=b&&a!=c&&a!=d&&a!=e&&a!=x
&&b!=c&&b!=d&&b!=e&&b!=x
&&c!=d&&c!=e&&c!=x
&&d!=e&&d!=x
&&e!=x){
int sum1=a*10000+b*1000+c*100+d*10+e;
int sum2=e*10000+d*1000+c*100+b*10+a;
if(sum1*x==sum2){
cout<<sum1<<" "<<x;
}
}
}
}
}
}
}
}
}