您的位置:首页 > 其它

蓝桥杯-古堡算式【枚举】

2018-02-04 23:33 218 查看
     福尔摩斯到某古堡探险,看到门上写着一个奇怪的算式:
    ABCDE * ? = EDCBA
    他对华生说:“ABCDE应该代表不同的数字,问号也代表某个数字!”
    华生:“我猜也是!”
    于是,两人沉默了好久,还是没有算出合适的结果来。
    请利用计算机的优势,找到破解的答案。
    把 ABCDE 所代表的数字写出来。

#include<stdio.h>
int main()
{
int a,b,c,d,e,x;
for( a=0; a<=9; a++)
{
for( b=0; b<=9; b++)
{
if(a==b)
continue;
for( c=0; c<=9; c++)
{
if(a==b||b==c||a==c)
continue;
for( d=0; d<=9; d++)
{
if(a==b||a==c||a==d||b==c||b==d||c==d)
continue;
for(e=0; e<=9; e++)
{
if(a==b||a==c||a==d||a==e||b==c||b==d||b==e||c==d||c==e||d==e)
continue;
for(x=0; x<=9; x++)
{
int s1=a*10000+b*1000+c*100+d*10+e;
int s2=e*10000+d*1000+c*100+b*10+a;
if((s1*x)==s2)
{
printf("%d%d%d%d%d\n",a,b,c,d,e);
}
}
}
}
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: