蓝桥杯之最简单的爆破-----数字谜

来源:互联网 发布:正规网络博客平台 编辑:程序博客网 时间:2024/05/01 21:26

将a b c依次试探每一个可能解,约束条件是满足等式关系(abb)*b=acbc;

a(1-----9)  b(2------9)   c(0-----9)

#include<stdio.h>int main(){int a,b,c,temp1,temp2,flag=0;for(a=1;a<=9;a++)for(b=2;b<=9;b++)for(c=0;c<=8;c++){                   //三层for循环形成暴力搜索,试探每一个数的所有解temp1=a*100+b*10+b;temp2=a*1000+c*100+b*10+c;if(temp1*b==temp2){printf("%d\n%d\n%d\n",a,b,c);printf("%d*%d=%d\n",temp1,b,temp2);flag=1;}} if(flag==0)printf("no result");return 0;} 


0 0
原创粉丝点击