CF1602A.Two Subsequences

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a string ss. You need to find two non-empty strings aa and bb such that the following conditions are satisfied:

  1. Strings aa and bb are both subsequences of ss.
  2. For each index ii, character sis_i of string ss must belong to exactly one of strings aa or bb.
  3. String aa is lexicographically minimum possible; string bb may be any possible string.

Given string ss, print any valid aa and bb.

Reminder:

A string aa (bb) is a subsequence of a string ss if aa (bb) can be obtained from ss 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 xx is lexicographically smaller than a string yy if and only if one of the following holds:

  • xx is a prefix of yy, but x≠yx \ne y;
  • in the first position where xx and yy differ, the string xx has a letter that appears earlier in the alphabet than the corresponding letter in yy.

给你一个字符串 ss。你需要找到两个非空字符串 aa 和 bb,使得满足以下条件:

  1. 字符串 aa 和 bb 均为 ss 的子序列;
  2. 对于每个下标 ii,字符串 ss 中的字符 sis_i 恰好属于 aa 或 bb 中的一个;
  3. 字符串 aa 在所有可能方案中字典序最小;字符串 bb 可以是任意满足条件的字符串。

给定字符串 ss,请输出任意一组合法的 aa 和 bb。

提示:

字符串 aa(或 bb)是字符串 ss 的子序列,当且仅当 aa(或 bb)可通过从 ss 中删除若干(可能为零)个字符得到。例如,“dores”、“cf” 和 “for” 都是 “codeforces” 的子序列,而 “decor” 和 “fork” 则不是。

字符串 xx 字典序小于字符串 yy,当且仅当满足以下任一条件:

  • xx 是 yy 的真前缀(即 xx 是 yy 的前缀且 x≠yx \ne y);
  • 在 xx 与 yy 首次出现不同字符的位置上,xx 中该位置的字母在字母表中早于 yy 中对应位置的字母。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001 \le t \le 1000). Description of the test cases follows.

The first and only line of each test case contains one string ss (2≤∣s∣≤1002 \le |s| \le 100 where ∣s∣|s| means the length of ss). String ss consists of lowercase Latin letters.

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

每个测试用例仅有一行,包含一个字符串 ss(2≤∣s∣≤1002 \le |s| \le 100,其中 ∣s∣|s| 表示字符串 ss 的长度)。字符串 ss 由小写拉丁字母组成。

输出格式

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

对于每个测试用例,输出满足给定条件的字符串 aa 和 bb。若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    fc
    aaaa
    thebrightboiler

    输出#1

    c f
    a aaa
    b therightboiler

说明/提示

In the first test case, there are only two choices: either a=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 ss. The second string can be of two variants; one of them is given here.

在第一个测试用例中,仅有两种选择:要么 a=a = f 且 $b = $ c,要么 $a = $ c 且 $b = $ f。而 $a = $ c 在字典序上小于 $a = $ f。

在第二个测试用例中,字符串中唯一的字符是 a。

在第三个测试用例中,可以证明 b 是字符串 ss 的字典序最小的子序列。第二个字符串有两种可能的形式;其中一种已在本题中给出。

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

首页