string find_answer(int n, int m, double k) { if (k > pre[n][m]) return "Error !"; if (n == 0) return string(m, 'o'); if (m == 0) return string(n, '-'); //前半部分递归 if (k <= pre[n - 1][m]) return '-' + find_answer(n - 1, m, k); //后半部分递归,前半部分没有,所以要在后半部分找第k-number return 'o' + find_answer(n, m - 1, (k - pre[n - 1][m])); }
改为char q[10] = "Error!"; char w = '-'; char p = 'o'; char a[10] = "-"; char b[10] = "o";
int i; char c[maxn] = {}; char* aat; char* aas; char* find_answer(int n, int m, double k) {
if (k > pre[n][m])
return q;
if (n == 0)
{
for (i = 0; i < m; i++)
c[i] = p;
return c;
}
if (m == 0)
{
for (i = 0; i < n; i++)
c[i] = w;
return c;
}
//前半部分递归
if (k <= pre[n - 1][m])
{
/*strcat(a, c);*/
aat = find_answer(n - 1, m, k);
strcat(a, aat);
return a;
}
//后半部分递归,前半部分没有,所以要在后半部分找第k-number
/* strcat(b, c);*/
{ aas = find_answer(n, m - 1, (k - pre[n - 1][m]));
strcat(b, aas);;
return b; }
}
为什么不对,怎么改才行