有个等式DONALD + GERALD = ROBERT ,其中各字母对应0-9且各不相同,D=5。求C/C++源程序。答出另有加分

来源:百度知道 编辑:UC知道 时间:2024/05/16 09:22:49

#include <iostream>
using namespace std;
// DONALD + GERALD = ROBERT
//          A  B  D  E  G  L  N  O  R  T 
int v[]={-1,-1, 5,-1,-1,-1,-1,-1,-1,-1};
void display()
{
    int
    x=100000*v[2]+10000*v[7]+1000*v[6]+100*v[0]+10*v[5]+v[2],
    y=100000*v[4]+10000*v[3]+1000*v[8]+100*v[0]+10*v[5]+v[2],
    z=100000*v[8]+10000*v[7]+1000*v[1]+100*v[3]+10*v[8]+v[9];
    if(x+y==z) cout<<x<<'+'<<y<<'='<<z<<endl;
}    
void DFS(int depth)
{
    if(depth==10) {display();return;}