给定一个数字字符串,按字典序返回数字所有可能表示的字符串。
特殊符号不用考虑
输入
一行,一个数字字符串(保证长度小于1010且不包含0和1)
输入字符在 '2'
到 '9'
之间。
输出
按字典序输出所有可能的字符串,每种结果一行,最后需要换行
输入样例
23
输出样例
ad
ae
af
bd
be
bf
cd
ce
cf
#include<stdio.h>
void code(int data[],char word[][5],char shuchu[],int num,int n,int count);
int main()
{
char num[10]={'\0'},word[10][5]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};//0-9
int i,data[9]={0},n=0,count;
scanf("%s",num);
char shuchu[10]={'\0'};
for(i=0;num[i]!='\0';i++)
{
data[i]=num[i]-'0';
n++;
}
count=0;
code(data,word,shuchu,data[0],n,count);
return 0;
}
void code(int data[],char word[][5],char shuchu[],int num,int n,int count)
{
int j=0;
if(n==count+1)
{
for(j=0;word[num][j]!='\0';j++)
{
printf("%s%c\n",shuchu,word[num][j]);
}
shuchu[j-1]='\0';
}
else
{
for(j=0;word[num][j]!='\0';j++)
{
shuchu[count]=word[num][j];
count++;
code(data,word,shuchu,data[count],n,count);
count--;
}
}
}