CF1602A.Two Subsequences
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s. You need to find two non-empty strings a and b such that the following conditions are satisfied:
- Strings a and b are both subsequences of s.
- For each index i, character si of string s must belong to exactly one of strings a or b.
- String a is lexicographically minimum possible; string b may be any possible string.
Given string s, print any valid a and b.
Reminder:
A string a (b) is a subsequence of a string s if a (b) can be obtained from s by deletion of several (possibly, zero) elements. For example, "dores", "cf", and "for" are subsequences of "codeforces", while "decor" and "fork" are not.
A string x is lexicographically smaller than a string y if and only if one of the following holds:
- x is a prefix of y, but x=y;
- in the first position where x and y differ, the string x has a letter that appears earlier in the alphabet than the corresponding letter in y.
给你一个字符串 s。你需要找到两个非空字符串 a 和 b,使得满足以下条件:
- 字符串 a 和 b 均为 s 的子序列;
- 对于每个下标 i,字符串 s 中的字符 si 恰好属于 a 或 b 中的一个;
- 字符串 a 在所有可能方案中字典序最小;字符串 b 可以是任意满足条件的字符串。
给定字符串 s,请输出任意一组合法的 a 和 b。
提示:
字符串 a(或 b)是字符串 s 的子序列,当且仅当 a(或 b)可通过从 s 中删除若干(可能为零)个字符得到。例如,“dores”、“cf” 和 “for” 都是 “codeforces” 的子序列,而 “decor” 和 “fork” 则不是。
字符串 x 字典序小于字符串 y,当且仅当满足以下任一条件:
- x 是 y 的真前缀(即 x 是 y 的前缀且 x=y);
- 在 x 与 y 首次出现不同字符的位置上,x 中该位置的字母在字母表中早于 y 中对应位置的字母。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤1000). Description of the test cases follows.
The first and only line of each test case contains one string s (2≤∣s∣≤100 where ∣s∣ means the length of s). String s consists of lowercase Latin letters.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤1000)。随后是测试用例的描述。
每个测试用例仅有一行,包含一个字符串 s(2≤∣s∣≤100,其中 ∣s∣ 表示字符串 s 的长度)。字符串 s 由小写拉丁字母组成。
输出格式
For each test case, print the strings a and b that satisfy the given conditions. If there are multiple answers, print any.
对于每个测试用例,输出满足给定条件的字符串 a 和 b。若存在多个答案,输出任意一个即可。
输入输出样例
输入#1
3 fc aaaa thebrightboiler
输出#1
c f a aaa b therightboiler
说明/提示
In the first test case, there are only two choices: either a= f and $b = $ c or $a = $ c and $b = $ f. And $a = $c is lexicographically smaller than $a = $ f.
In the second test case, a is the only character in the string.
In the third test case, it can be proven that b is the lexicographically smallest subsequence of s. The second string can be of two variants; one of them is given here.
在第一个测试用例中,仅有两种选择:要么 a= f 且 $b = $ c,要么 $a = $ c 且 $b = $ f。而 $a = $ c 在字典序上小于 $a = $ f。
在第二个测试用例中,字符串中唯一的字符是 a。
在第三个测试用例中,可以证明 b 是字符串 s 的字典序最小的子序列。第二个字符串有两种可能的形式;其中一种已在本题中给出。
输入解题思路,AI测评打分。不知道怎么写?