第二题(NOIP2008)
#include<iostream>
#include<cstring>
using namespace std;
#define MAX 100
void solve(char first[], int spos_f, int epos_f, char mid[], int spos_m, int epos_m) {
int i, root_m;
if (spos_f > epos_f)
return;
for (i = spos_m; i <= epos_m; i++)
if (first[spos_f] == mid[i]) {
root_m = i;
break;
}
solve(first, spos_f + 1, spos_f + (root_m - spos_m), mid, spos_m, root_m - 1);
solve(first, spos_f + (root_m - spos_m) + 1, epos_f, mid, root_m + 1, epos_m);
cout << first[spos_f];
}
int main() {
char first[MAX], mid[MAX];
int len;
cin >> len;
cin >> first >> mid;
solve(first, 0, len - 1, mid, 0, len - 1);
cout << endl;
return 0;
}
- 【判断题】将25行移到22行和23行之间,程序不会出错。
{{ select(1) }}
- 【判断题】将09行和10行去掉,程序可以得出相同的结果。
{{ select(2) }}
- 【判断题】该程序的时间复杂度为O(n)。
{{ select(3) }}
- 【判断题】将25行的char改为int类型,程序可以得到相同的结果。
{{ select(4) }}
- 【选择题】输入为7\nABDCEGF\nBDAGECF时,输出为( )。
{{ select(5) }}
- DBGEFCA
- DBGFECA
- GBDEFCA
- ABCDEFG
- 【选择题】该程序要解决的问题是( )。
{{ select(6) }}
- 给出先序遍历和后序遍历求中序遍历
- 给出先序遍历和中序遍历求后序遍历
- 给出中序遍历和后序遍历求前序遍历
- 给出前序遍历和中序遍历求层序遍历