Google puzzle

  1. Solve this cryptic equation, realizing of course that values for M and E could be interchanged. No leading zeros are allowed.

  WWWDOT - GOOGLE = DOTCOM

虽然找到O+L = O 或者 O - 9 -1 = O的规律,但是还是认为自己大脑再行穷举路径太多了。所以重用了自己过去的代码解决了。

// 验证函数
bool  IsCorrent( int   *  dest)
{
    
int wwwdot = dest[0]*(100000+10000+1000)+dest[1]*100+dest[2]*10+dest[3];
    
int google = dest[4]*(100000+100)+dest[2]*(10000+1000)+dest[5]*10+dest[6];
    
int dotcom = dest[1]*100000+dest[2]*(10000+10)+dest[3]*1000+dest[7]*100+dest[8];
    
if(wwwdot - google == dotcom)
    
{
        
return true;
    }

    
else
    
{
        
return false;
    }

}


// 求子集函数
void  All( int   *  src, int  currentIndex, int  len, int *  dest, int  num)
{
    
if(currentIndex == len)
        
return;
    dest[num
++= src[currentIndex++];
    
if(num == 9)
    
{
        Perm(dest,
0,8,9);
    }

    All(src,currentIndex,len,dest,num);
    All(src,currentIndex,len,dest,num
-1);
}



// 求排列函数
void  Perm( int   *  src, int  current,  int  lesslen, int  len)
{
    
if(current == lesslen)
    
{
        
if(IsCorrent(src))
        
{
            
for(int i = 0; i < len; i++)
            
{
                cout 
<< src[i]<<" ";
            }

            cout 
<< endl;
        }

    }


    
for(int i = current; i < len; i++)
    
{
        swap(src[i],src[current]);
        Perm(src,current
+1,lesslen,len);
        swap(src[i],src[current]);
    }


}

 

最后:

WDOTGLECM分别为7 5 8 9 1 0 6 4 3或7 5 8 9 1 0 3 4 6因为E和M可以互换,所以正解.....

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值