UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205940#883. 求先序排列Soulmate1002ms1220kbC++11609b2024-07-20 18:05:252024-07-20 20:04:39

answer

#include <bits/stdc++.h>
using namespace std;

void printPreorder(string& inorder,int s,int e,string& postorder,int S,int E) 
{  
    if (s>e) return; 
  
   
    char root=postorder[E];  
    cout<<root; 
  
    int rt=inorder.find(root,s);  
    printPreorder(inorder,s,rt-1,postorder,S,S+rt-s-1);  
    printPreorder(inorder,rt+1,e,postorder,S+rt-s,E-1);  
}  
  
int main() 
{  
    string inorder; 
    string postorder; 
    cin>>inorder>>postorder;
  
    
    printPreorder(inorder,0,inorder.size()-1,postorder,0,postorder.size()-1);  
    cout<<endl;  
  
    return 0;  
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 20
Accepted
time: 0ms
memory: 1216kb

input:

ACEB
AEBC

output:

CABE

result:

ok single line: 'CABE'

Test #2:

score: 20
Accepted
time: 0ms
memory: 1216kb

input:

BAC
BCA

output:

ABC

result:

ok single line: 'ABC'

Test #3:

score: 20
Accepted
time: 1ms
memory: 1216kb

input:

DEABFCHG
DEAFHGCB

output:

BAEDCFGH

result:

ok single line: 'BAEDCFGH'

Test #4:

score: 20
Accepted
time: 0ms
memory: 1216kb

input:

DCBA
DCBA

output:

ABCD

result:

ok single line: 'ABCD'

Test #5:

score: 20
Accepted
time: 1ms
memory: 1220kb

input:

CBAFEGD
CFGEADB

output:

BCDAEFG

result:

ok single line: 'BCDAEFG'