A14577 | Two Subsequences
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
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.
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted