char * recursivecombo(char *str, int choices, int level)
{
int len = strlen(str);
level++;
if( level == choices)
{
for (int i = 0; i < len -2; i++)
{
printf("%c", str[i]) ;
}
}
else
{
for (int i = 0; i < len - 2; i++)
{
printf("%c",str[i]);
recursivecombo(str.substr(1), level);
}
}
}
我想使用字符串而不是 char*。
std::string recursivecombo(const std::string& str, int choices, int level)
{
level++;
for (int i = 0; i < str.length() -2; ++i)
{
cout<<str.at(i) ;
if( level != choices)
recursivecombo(str.substr(1),8,/*Missing choce*/ level);
}
/*Missing return value*/
}
这只是一个使用字符串的模型。您的功能存在一些问题
1)你的返回值在哪里
2)如果你打算使用字符串,请使用cout,而不是printf,如果它是C++
3)使用前缀++。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)