ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205968 | #883. 求先序排列 | cql | 100 | 0ms | 1212kb | C++11 | 556b | 2024-07-20 18:24:27 | 2024-07-20 20:09:48 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
string a, b;
int findEnd(string s, int r) {
int res;
for (res = r; ; res--) {
int i = s.find(b[res]);
if (i != -1)
return res;
}
}
void fn(int l, int r, char c) {
if (l > r) return;
cout << c;
int idx = a.find(c);
if (idx > l)
fn(l, idx - 1, b[findEnd(a.substr(l, idx - l), idx - 1)]);
if (idx < r)
fn(idx + 1, r, b[findEnd(a.substr(idx + 1, r - idx), r)]);
}
signed main() {
cin >> a >> b;
fn(0, b.size() - 1, b.back());
return 0;
}
详细
小提示:点击横条可展开更详细的信息
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: 1208kb
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'