电话号码对应英语单词

其实就是搜索解答树的暴利搜索。

编程之美P222

#include <iostream>
using namespace std;

char c[10][10]={
    "","","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"
};
int total[10]={0,0,3,3,3,3,3,4,3,4};

void recursiveSearch(int number[],int answer[],int telLen,int cur){
    if(cur==telLen){
        for(int j=0;j<telLen;j++){
            cout<<c[number[j]][answer[j]];
        }
        cout<<endl;
        return;//需要return
    }

    for(int i=0;i<total[number[cur]];i++){
        answer[cur]=i;
        recursiveSearch(number,answer,telLen,cur+1);
    }
    if(total[number[cur]]==0){
        answer[cur]=0;
        recursiveSearch(number,answer,telLen,cur+1);
    }
}



int main() {

    int number[]={9,2,1};
    int answer[10];

    recursiveSearch(number,answer,3,0);

    return 0;
}
    原文作者:知之可否
    原文地址: https://blog.csdn.net/gao1440156051/article/details/51682461
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞