0 of 1 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 1 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
阅读程序写结果: (2008年真题)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#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; } |
输入:
7
ABDCEGF
BDAGECF
输出为: