更新时间:2018-11-22 16:19作者:王华老师
#include
#include
#define N 4 //电话号码个数
using namespace std;
char c[][10] = {"","","ABC","DEF","GHI","JKL","MNO","PQRS","TUV","WXYZ"};//存储各个数字所能代表的字符
int number[N] = {2, 4 ,7, 9}; //存储电话号码
int total[10] = {0, 0, 3, 3, 3, 3, 3, 4, 3, 4}; //各个数组所能代表的字符总数
int answer[N]; //数字目前所代表的字符在其所能代表的字符集中的位置,初始为0
void Search(int *number, int n); //非递归的办法
void RecursiveSearch(int *number, int cur, char *ps, int n); //递归的办法
int main()
{
//Search(number, N);
char ps[N+1] = {0};
RecursiveSearch(number, 0, ps, N);
return 0;
}
void Search(int *number, int n)
{
int i;
while(1)
{
for(i=0; i
printf("%c", c[number[i]][answer[i]]);
printf("\n");
int k = n-1; //用k和while循环来解决扩展性问题,模拟了递归