CF1506G.Maximize the Remaining String
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s , consisting of lowercase Latin letters. While there is at least one character in the string s that is repeated at least twice, you perform the following operation:
- you choose the index i ( 1≤i≤∣s∣ ) such that the character at position i occurs at least two times in the string s , and delete the character at position i , that is, replace s with s1s2…si−1si+1si+2…sn .
For example, if s= "codeforces", then you can apply the following sequence of operations:
- i=6⇒s= "codefrces";
- i=1⇒s= "odefrces";
- i=7⇒s= "odefrcs";
Given a given string s , find the lexicographically maximum string that can be obtained after applying a certain sequence of operations after which all characters in the string become unique.
A string a of length n is lexicographically less than a string b of length m , if:
- there is an index i ( 1≤i≤min(n,m) ) such that the first i−1 characters of the strings a and b are the same, and the i -th character of the string a is less than i -th character of string b ;
- or the first min(n,m) characters in the strings a and b are the same and n<m .
For example, the string a= "aezakmi" is lexicographically less than the string b= "aezus".
输入格式
The first line contains one integer t ( 1≤t≤104 ). Then t test cases follow.
Each test case is characterized by a string s , consisting of lowercase Latin letters ( 1≤∣s∣≤2⋅105 ).
It is guaranteed that the sum of the lengths of the strings in all test cases does not exceed 2⋅105 .
输出格式
For each test case, output the lexicographically maximum string that can be obtained after applying a certain sequence of operations after which all characters in the string become unique.
输入输出样例
输入#1
6 codeforces aezakmi abacaba convexhull swflldjgpaxs myneeocktxpqjpz
输出#1
odfrces ezakmi cba convexhul wfldjgpaxs myneocktxqjpz