首页 > 学院 > 开发设计 > 正文

猜灯谜

2019-11-08 02:35:55
字体:
来源:转载
供稿:网友
 A村的元宵节灯会上有一迷题:请猜谜 * 请猜谜 = 请边赏灯边猜小明想,一定是每个汉字代表一个数字,不同的汉字代表不同的数字。  请你用计算机按小明的思路算一下,每个汉字代表的数字。

#include<cstdio>

#include<iostream>

using namespace std;

 

int a[6];

bool book[10];

void   fun(int step)

{  

    int i,y;

     

if (step==6)

 //int y=a[0]*100+a[1]*10+a[2];

    // int x=a[0]*100000+a[3]*10000+a[4]*1000+a[5]*100+a[3]*10+a[1];

{

int y=a[0]*100+a[1]*10+a[2];

    int x=a[0]*100000+a[3]*10000+a[4]*1000+a[5]*100+a[3]*10+a[1];

if(x==(y*y))

PRintf("%d%d%d",a[0],a[1],a[2]);

return ;

}  

for(i=0;i<=9;i++)

 {

if(book[i]==0)

{

a[step]=i;

book[i]=true ;

fun(step+1);

book[i]=false;  

  }

 }

 return ;  

}

int main()

{

     fun(0);

     return 0;

 } 


上一篇:字符串的全排列

下一篇:奇妙的数字

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表