CF1617A.Forbidden Subsequence

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given strings SS and TT, consisting of lowercase English letters. It is guaranteed that TT is a permutation of the string abc.

Find string S′S', the lexicographically smallest permutation of SS such that TT is not a subsequence of S′S'.

String aa is a permutation of string bb if the number of occurrences of each distinct character is the same in both strings.

A string aa is a subsequence of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) elements.

A string aa is lexicographically smaller than a string bb if and only if one of the following holds:

  • aa is a prefix of bb, but a≠ba \ne b;
  • in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb.

给定两个字符串 SS 和 TT,均由小写英文字母组成。保证 TT 是字符串 abc 的一个排列。

请找出字符串 S′S',它是 SS 的字典序最小的排列,且满足 TT 不是 S′S' 的子序列。

若两个字符串中每个不同字符的出现次数均相同,则称字符串 aa 是字符串 bb 的一个排列。

若字符串 aa 可通过从字符串 bb 中删除若干(可能为零个或全部)字符得到,则称字符串 aa 是字符串 bb 的一个子序列。

当且仅当以下任一条件成立时,字符串 aa 字典序小于字符串 bb:

  • aa 是 bb 的真前缀(即 aa 是 bb 的前缀且 a≠ba \ne b);
  • 在 aa 与 bb 首次出现不同字符的位置上,aa 中该位置的字母在字母表中先于 bb 中对应位置的字母。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤10001 \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 SS (1≤∣S∣≤1001 \le |S| \le 100), consisting of lowercase English letters.

The second line of each test case contains a string TT that is a permutation of the string abc. (Hence, ∣T∣=3|T| = 3).

Note that there is no limit on the sum of ∣S∣|S| across all test cases.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个字符串 SS(1≤∣S∣≤1001 \le |S| \le 100),由小写英文字母组成。

每个测试用例的第二行包含一个字符串 TT,它是字符串 abc 的一个排列。(因此,∣T∣=3|T| = 3。)

注意:所有测试用例的 ∣S∣|S| 总和没有限制。

输出格式

For each test case, output a single string S′S', the lexicographically smallest permutation of SS such that TT is not a subsequence of S′S'.

对于每个测试用例,输出一个字符串 S′S',它是 SS 的字典序最小的排列,且 TT 不是 S′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.

在第一个测试用例中,aaaabbc 和 aaaabcb 都字典序小于 aaaacbb,但它们都包含 abc 作为子序列。

在第二个测试用例中,abccc 是 cccba 的最小排列,且不包含 acb 作为子序列。

在第三个测试用例中,bcdis 是 dbsic 的最小排列,且不包含 bac 作为子序列。

输入解题思路,AI测评打分。不知道怎么写?

首页