# 编程之美读书笔记-电话号码对应英语单词

#include <iostream>
using namespace std;
#define TellLength 11

//将每个数字所能代表的字符记录在一个二维数组中，其中假设0、1所代表的字符为空字符
char c[10][10] =
{
"",        //0
"",        //1
"ABC",     //2
"DEF",     //3
"GHI",     //4
"JKL",     //5
"MNO",     //6
"PQRS",    //7
"TUV",     //8
"WXYZ"     //9
};
//将每个数字所能代表的字母的总数记录在total数组中
int total[10] = { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4 };
//将电话号码记录在number数组中
int number[TellLength];

int main()
{
number[0] = 1;
number[1] = 8;
number[2] = 7;
number[3] = 0;
number[4] = 1;
number[5] = 1;
number[6] = 2;
number[7] = 7;
number[8] = 7;
number[9] = 2;
number[10] = 0;
while (true)
{
for (int i = 0; i < TellLength; i++) printf("%c", c[number[i]][answer[i]]);
printf("\n");
int k = TellLength - 1;
while (k>=0)
{
if (answer[k] < total[number[k]] - 1)
{
break;
}
else
{
k--;
}
}
if (k < 0) break;
}
return 0;
}

#include <iostream>
using namespace std;
#define TellLength 11

//将每个数字所能代表的字符记录在一个二维数组中，其中假设0、1所代表的字符为空字符
char c[10][10] =
{
"",        //0
"",        //1
"ABC",     //2
"DEF",     //3
"GHI",     //4
"JKL",     //5
"MNO",     //6
"PQRS",    //7
"TUV",     //8
"WXYZ"     //9
};
//将每个数字所能代表的字母的总数记录在total数组中
int total[10] = { 0, 0, 3, 3, 3, 3, 3, 4, 3, 4 };
//将电话号码记录在number数组中
int number[TellLength];

void RecursiveSearch(int *number, int *answer, int index)
{
if (index == TellLength-1)
{
for (int i = 0; i < TellLength; i++) printf("%c", c[number[i]][answer[i]]);
printf("\n");
return;
}
if(total[number[index]]==0) RecursiveSearch(number, answer, index + 1);
}

int main()
{
number[0] = 1;
number[1] = 8;
number[2] = 7;
number[3] = 0;
number[4] = 1;
number[5] = 1;
number[6] = 2;
number[7] = 7;
number[8] = 7;
number[9] = 2;
number[10] = 0;
}