递归出所有的字符串,实在是不怎么会~写不出来了。。。希望各位指点一下啊
题:2,3,4,5,6,7,8,9,所代表的字母2: A,B,C 5: J,K,L 8: T,U,V
3: D,E,F 6: M,N,O 9: W,X,Y
4: G,H,I 7: P,R,S
例如:数字4734产生的字母序列是以下:
GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDI
GREG GREH GREI GRFG GRFH GRFI GSDG GSDH GSDI GSEG GSEH GSEI
GSFG GSFH GSFI HPDG HPDH HPDI HPEG HPEH HPEI HPFG HPFH HPFI
HRDG HRDH HRDI HREG HREH HREI HRFG HRFH HRFI HSDG HSDH HSDI
HSEG HSEH HSEI HSFG HSFH HSFI IPDG IPDH IPDI IPEG IPEH IPEI
IPFG IPFH IPFI IRDG IRDH IRDI IREG IREH IREI IRFG IRFH IRFI
ISDG ISDH ISDI ISEG ISEH ISEI ISFG ISFH ISFI
想用递归但是不怎么会写。。。
#include <stdio.h>
#include <string.h>
#define MAXSIZE 100
int count=0,i;
char *result[MAXSIZE];
char str[MAXSIZE];
char phoneKey[8][3]={{'A','B','C'},{'D','E','F'},
{'G','H','I'},{'J','K','L'},
{'M','N','O'},{'P','R','S'},
{'T','U','V'},{'W','X','Y'}};
//递归所有字符串
void allstring(int dig ,int num)
{
if(num==-1)
{
str[4-num]='\0';
strcpy(result[count],str);
count++;
return ;}
else if(num>=0){
str[4-num]=phoneKey[dig][i];
}
}
void main()
{
int digits[4]={2,5,1,2};
allstring( ,4)
}