标签:mem ios sizeof stage RoCE 技术分享 each hose cat
Description
 
Input
Output
Sample Input
BDHPY CM GQ K * AC B $
Sample Output
KGCBDHQMPY BAC
题目大意:
? ?棵?叉搜索树,每次揪掉当前所有叶?,作为??输?。
? 请输出原树的前序遍
解题思路:
? 输?倒着看。
? 最后?轮揪掉的?定是根。
? 其他轮的只需要按照?叉树要求依次插?到叶?上即可。
? 复原之后做前序遍
AC代码:
 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cstdio>
 5 using namespace std;
 6 int n;
 7 char a[1005];
 8 struct kkk{
 9     int lson,rson;//左儿子、右儿子 
10     char qwq;//节点信息 
11 }tr[104];
12 void build(int h,char ch) {
13     if(tr[h].qwq == 0){//根节点 
14         tr[h].qwq = ch;
15         return ;
16     }
17     else if(tr[h].qwq > ch) { 
18         if(!tr[h].lson) tr[h].lson=n++;
19         build(tr[h].lson,ch);
20     }
21     else if(tr[h].qwq <= ch) {
22         if(!tr[h].rson) tr[h].rson=n++;
23         build(tr[h].rson,ch);
24     }
25 }
26 void ans(int d) {//求先序遍历 
27     if(!tr[d].qwq) return ;
28     cout << tr[d].qwq;
29     ans(tr[d].lson);
30     ans(tr[d].rson);
31 }
32 int main() {
33     while(scanf("%s",a)) {
34         char x; n=2;
35         int len = strlen(a);
36         memset(tr,0, sizeof(tr));
37         while(true) {
38             cin>>x;
39             if(x == ‘*‘||x == ‘$‘) break;
40             a[len++] = x;
41         }
42         for(int i = len-1; i >= 0; i--) build(1, a[i]);//倒着建树 
43         ans(1);
44         cout<<endl;
45         if(x == ‘$‘) return 0;
46     }
47 }
标签:mem ios sizeof stage RoCE 技术分享 each hose cat
原文地址:https://www.cnblogs.com/lipeiyi520/p/10336565.html