ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205983 | #883. 求先序排列 | kevin0625 | 100 | 1ms | 1228kb | C++ | 689b | 2024-07-20 18:34:38 | 2024-07-20 20:11:55 |
answer
#include<bits/stdc++.h>
using namespace std;
string preorder(string inorder,string postorder)
{
if(inorder.length()<=1)
return inorder;
char root=postorder[postorder.length()-1];
int pos=inorder.find(root);
string inorder_left=inorder.substr(0,pos);
string inorder_right=inorder.substr(pos+1);
string postorder_left=postorder.substr(0,inorder_left.length());
string postorder_right=postorder.substr(inorder_left.length(),inorder_right.length());
return root+preorder(inorder_left,postorder_left)+preorder(inorder_right,postorder_right);
}
int main()
{
string inorder,postorder;
cin>>inorder>>postorder;
cout<<preorder(inorder,postorder)<<endl;
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 20
Accepted
time: 0ms
memory: 1224kb
input:
ACEB AEBC
output:
CABE
result:
ok single line: 'CABE'
Test #2:
score: 20
Accepted
time: 0ms
memory: 1228kb
input:
BAC BCA
output:
ABC
result:
ok single line: 'ABC'
Test #3:
score: 20
Accepted
time: 0ms
memory: 1224kb
input:
DEABFCHG DEAFHGCB
output:
BAEDCFGH
result:
ok single line: 'BAEDCFGH'
Test #4:
score: 20
Accepted
time: 1ms
memory: 1224kb
input:
DCBA DCBA
output:
ABCD
result:
ok single line: 'ABCD'
Test #5:
score: 20
Accepted
time: 0ms
memory: 1228kb
input:
CBAFEGD CFGEADB
output:
BCDAEFG
result:
ok single line: 'BCDAEFG'