UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205998#883. 求先序排列shawn1000ms1212kbC++628b2024-07-20 18:44:372024-07-20 20:13:55

answer

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

string dfs(string z,string q,int step){
	if (z.length()<=1)  return z;
	int tmp=z.length()-1;
	char root=q[tmp];
	//cout<<root<<" "; 
	int pos=z.find(root);
	string z_l=z.substr(0,pos);
	//cout<<z_l<<" ";
	string z_r=z.substr(pos+1);
	//cout<<z_r<<" ";
	string q_l=q.substr(0,z_l.length());
	//cout<<q_l<<" ";
	string q_r=q.substr(z_l.length());
	//cout<<q_r<<endl;
	return root+dfs(z_l,q_l,step-1)+dfs(z_r,q_r,step-1);
}

int main(){
	string sz,sq;
	cin>>sz>>sq;
	cout<<dfs(sz,sq,0);
	return 0;
} 
/*
zhong:
hou:
ABEDFCHG
AEFDBHGC
qian:CBADEFGH 
*/

详细

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

Test #1:

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

input:

ACEB
AEBC

output:

CABE

result:

ok single line: 'CABE'

Test #2:

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

input:

BAC
BCA

output:

ABC

result:

ok single line: 'ABC'

Test #3:

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

input:

DEABFCHG
DEAFHGCB

output:

BAEDCFGH

result:

ok single line: 'BAEDCFGH'

Test #4:

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

input:

DCBA
DCBA

output:

ABCD

result:

ok single line: 'ABCD'

Test #5:

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

input:

CBAFEGD
CFGEADB

output:

BCDAEFG

result:

ok single line: 'BCDAEFG'