40 lines
876 B
C
40 lines
876 B
C
|
|
#include <stdio.h>
|
||
|
|
|
||
|
|
void trace(int i, int j, int s[][5]) {
|
||
|
|
if (i == j) {
|
||
|
|
printf("A%d", i);
|
||
|
|
} else {
|
||
|
|
printf("(");
|
||
|
|
trace(i, s[i][j], s); // 递归输出左边
|
||
|
|
trace(s[i][j] + 1, j, s); // 递归输出右边
|
||
|
|
printf(")");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
int wei[] = { 2, 3, 4, 5, 6 };
|
||
|
|
int s[5][5] = {
|
||
|
|
{0, 0, 0, 0, 0},
|
||
|
|
{0, 0, 1, 2, 2},
|
||
|
|
{0, 0, 0, 2, 2},
|
||
|
|
{0, 0, 0, 0, 3},
|
||
|
|
{0, 0, 0, 0, 0}
|
||
|
|
};
|
||
|
|
|
||
|
|
// 打印二维数组 s 的特定格式
|
||
|
|
for (int i = 0; i < 5; i++) {
|
||
|
|
for (int j = 0; j < 5; j++) {
|
||
|
|
if (i == j || i + j == 4) // wei.length - 1 = 4
|
||
|
|
printf("%d", s[i][j]);
|
||
|
|
printf("\t");
|
||
|
|
}
|
||
|
|
printf("\n");
|
||
|
|
}
|
||
|
|
|
||
|
|
// 打印括号表示法
|
||
|
|
trace(1, 4, s); // wei.length - 1 = 4
|
||
|
|
printf("\n");
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|