UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205939#883. 求先序排列hujunyi661001ms1148kbC++485b2024-07-20 18:04:352024-07-20 20:04:29

answer

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char s1[10];
char s2[10];
int len;
inline int find(char ch)
{
    for(int i=0;i<len;i++)
    {
        if(s1[i]==ch) return i;
    }
}
void dfs(int l1,int r1,int l2,int r2)
{
    int m=find(s2[r2]);
    cout<<s2[r2];
    if(m>l1) dfs(l1,m-1,l2,r2-r1+m-1);
    if(m<r1) dfs(m+1,r1,l2+m-l1,r2-1);
}
int main()
{
    cin>>s1;
    cin>>s2;
    len=strlen(s1);
    dfs(0,len-1,0,len-1);
}

详细

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

Test #1:

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

input:

ACEB
AEBC

output:

CABE

result:

ok single line: 'CABE'

Test #2:

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

input:

BAC
BCA

output:

ABC

result:

ok single line: 'ABC'

Test #3:

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

input:

DEABFCHG
DEAFHGCB

output:

BAEDCFGH

result:

ok single line: 'BAEDCFGH'

Test #4:

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

input:

DCBA
DCBA

output:

ABCD

result:

ok single line: 'ABCD'

Test #5:

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

input:

CBAFEGD
CFGEADB

output:

BCDAEFG

result:

ok single line: 'BCDAEFG'