考虑一个将字母转换为整数的编码系统,其中“a”表示为 1,“b”表示为 2,..“z”表示为 26。给定一个数字数组(1 到 9)作为输入,编写一个打印所有输入数组的有效解释。
/*Examples
Input: {1, 1}
Output: ("aa", 'k")
[2 interpretations: aa(1, 1), k(11)]
Input: {1, 2, 1}
Output: ("aba", "au", "la")
[3 interpretations: aba(1,2,1), au(1,21), la(12,1)]
Input: {9, 1, 8}
Output: {"iah", "ir"}
[2 interpretations: iah(9,1,8), ir(9,18)]*/
我的c代码
#include<iostream>
using namespace std;
#include<string.h>
int a[10]={2,3,4,4,2,4,2,8,9};
char c[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
void func(int i,char result[10])
{
if(i==10)
{
int l=strlen(result);
for(int j=0;j<l;j++)
cout<<result[j];
}
else
{
if(10*a[i]+a[i+1]<26)
{
strcat(result,"c[10*a[i]+a[i+1]]");
func(i+2,result);
}
strcat(result,"c[a[i]]");
func(i+1,result);
}
}
int main()
{
func(0,"");
}
我无法找出错误。你能帮我吗??