A14680 | Forbidden Subsequence
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given strings $S$ and $T$ , consisting of lowercase English letters. It is guaranteed that $T$ is a permutation of the string abc.
Find string $S'$ , the lexicographically smallest permutation of $S$ such that $T$ is not a subsequence of $S'$ .
String $a$ is a permutation of string $b$ if the number of occurrences of each distinct character is the same in both strings.
A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements.
A string $a$ is lexicographically smaller than a string $b$ if and only if one of the following holds:
- $a$ is a prefix of $b$ , but $a \ne b$ ;
- in the first position where $a$ and $b$ differ, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$ .
Find string $S'$ , the lexicographically smallest permutation of $S$ such that $T$ is not a subsequence of $S'$ .
String $a$ is a permutation of string $b$ if the number of occurrences of each distinct character is the same in both strings.
A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements.
A string $a$ is lexicographically smaller than a string $b$ if and only if one of the following holds:
- $a$ is a prefix of $b$ , but $a \ne b$ ;
- in the first position where $a$ and $b$ differ, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$ .
输入格式
Each test contains multiple test cases. The first line contains a single integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases. Description of the test cases follows.
The first line of each test case contains a string $S$ ( $1 \le |S| \le 100$ ), consisting of lowercase English letters.
The second line of each test case contains a string $T$ that is a permutation of the string abc. (Hence, $|T| = 3$ ).
Note that there is no limit on the sum of $|S|$ across all test cases.
The first line of each test case contains a string $S$ ( $1 \le |S| \le 100$ ), consisting of lowercase English letters.
The second line of each test case contains a string $T$ that is a permutation of the string abc. (Hence, $|T| = 3$ ).
Note that there is no limit on the sum of $|S|$ across all test cases.
输出格式
For each test case, output a single string $S'$ , the lexicographically smallest permutation of $S$ such that $T$ is not a subsequence of $S'$ .
输入输出样例
输入 #1
7 abacaba abc cccba acb dbsic bac abracadabra abc dddddddddddd cba bbc abc ac abc
输出 #1
aaaacbb abccc bcdis aaaaacbbdrr dddddddddddd bbc ac
In the first test case, both aaaabbc and aaaabcb are lexicographically smaller than aaaacbb, but they contain abc as a subsequence.
In the second test case, abccc is the smallest permutation of cccba and does not contain acb as a subsequence.
In the third test case, bcdis is the smallest permutation of dbsic and does not contain bac as a subsequence.
In the second test case, abccc is the smallest permutation of cccba and does not contain acb as a subsequence.
In the third test case, bcdis is the smallest permutation of dbsic and does not contain bac as a subsequence.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted