308944: CF1602A. Two Subsequences

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Two Subsequences

题意翻译

#### 题意翻译 给你一个字符串 $s$。你需要两个非空字符串 $a$ 和 $b$ 并且满足下面的条件: 1. 字符串 $a$ 和 $b$ 都是 $s$ 的子串。 2. 对于原字符串的每一个字符,必须属于 $a$ 和 $b$ 之一。 3. $a$ 是所有满足条件的字符串中字典序最小的。 给你 $s$,输出 $a$ 和 $b$。 注意: 如果可以通过删除几个(可能为零)元素从 $s$ 获得 a(b),那么字符串 a(b) 是字符串s的子序列。例如,“Dores”、“cf”和“for”是“codeforces”的子序列,而“Decor”和“fork”则不是。 字符串 $x$ 比字符串 $y$ 字典序小当且仅当 - $x$ 是 $y$ 的前缀,但 $x\ne y$ - 在 $x$ 和 $y$ 不同的第一个位置,$x$ 中的相应字母在字母表中出现的位置早于 $y$ 中的相应字母。 #### 输入格式 多组数据。 第一行一个整数 $T$,表示数据组数。对于每组数据,第一行一个字符串 $s$,意义如上文所示。 #### 输出格式 对于每组数据,输出满足要求的字符串 $a$,$b$。如果有多个答案,任意输出一个即可。 #### 数据范围 $1\le t\le 1000, 2\le |s| \le 100$ $|s|$ 表示 $s$ 的长度。 译者:@smyslenny

题目描述

You are given a string $ s $ . You need to find two non-empty strings $ a $ and $ b $ such that the following conditions are satisfied: 1. Strings $ a $ and $ b $ are both subsequences of $ s $ . 2. For each index $ i $ , character $ s_i $ of string $ s $ must belong to exactly one of strings $ a $ or $ b $ . 3. 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 \ne 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 $ .

输入输出格式

输入格式


Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 1000 $ ). Description of the test cases follows. The first and only line of each test case contains one string $ s $ ( $ 2 \le |s| \le 100 $ where $ |s| $ means the length of $ s $ ). String $ s $ consists of lowercase Latin letters.

输出格式


For each test case, print the strings $ a $ and $ b $ that satisfy the given conditions. If there are multiple answers, print any.

输入输出样例

输入样例 #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.

Input

题意翻译

#### 题意翻译 给你一个字符串 $s$。你需要两个非空字符串 $a$ 和 $b$ 并且满足下面的条件: 1. 字符串 $a$ 和 $b$ 都是 $s$ 的子串。 2. 对于原字符串的每一个字符,必须属于 $a$ 和 $b$ 之一。 3. $a$ 是所有满足条件的字符串中字典序最小的。 给你 $s$,输出 $a$ 和 $b$。 注意: 如果可以通过删除几个(可能为零)元素从 $s$ 获得 a(b),那么字符串 a(b) 是字符串s的子序列。例如,“Dores”、“cf”和“for”是“codeforces”的子序列,而“Decor”和“fork”则不是。 字符串 $x$ 比字符串 $y$ 字典序小当且仅当 - $x$ 是 $y$ 的前缀,但 $x\ne y$ - 在 $x$ 和 $y$ 不同的第一个位置,$x$ 中的相应字母在字母表中出现的位置早于 $y$ 中的相应字母。 #### 输入格式 多组数据。 第一行一个整数 $T$,表示数据组数。对于每组数据,第一行一个字符串 $s$,意义如上文所示。 #### 输出格式 对于每组数据,输出满足要求的字符串 $a$,$b$。如果有多个答案,任意输出一个即可。 #### 数据范围 $1\le t\le 1000, 2\le |s| \le 100$ $|s|$ 表示 $s$ 的长度。 译者:@smyslenny

加入题单

算法标签: