CF1076A.Minimizing the String
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s consisting of n lowercase Latin letters.
You have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation.
String s=s1s2…sn is lexicographically smaller than string t=t1t2…tm if n<m and s1=t1,s2=t2,…,sn=tn or there exists a number p such that p≤min(n,m) and s1=t1,s2=t2,…,sp−1=tp−1 and sp<tp.
For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".
给你一个由 n 个小写拉丁字母组成的字符串 s。
你需要至多删除该字符串中的一个字符(即删除零个或一个字符),使得所得字符串在所有通过此操作可能得到的字符串中字典序最小。
字符串 s=s1s2…sn 的字典序小于字符串 t=t1t2…tm,当且仅当以下条件之一成立:
- n<m,且 s1=t1,s2=t2,…,sn=tn;
- 或存在某个数 p,满足 p≤min(n,m),且 s1=t1,s2=t2,…,sp−1=tp−1,同时 sp<tp。
例如,“aaa” 小于 “aaaa”,“abb” 小于 “abc”,“pqr” 小于 “z”。
输入格式
The first line of the input contains one integer n (2≤n≤2⋅105) — the length of s.
The second line of the input contains exactly n lowercase Latin letters — the string s.
输入的第一行包含一个整数 n(2≤n≤2⋅105)—— 字符串 s 的长度。
输入的第二行恰好包含 n 个小写拉丁字母 —— 字符串 s。
输出格式
Print one string — the smallest possible lexicographically string that can be obtained by removing at most one character from the string s.
输出一个字符串——即通过从字符串 s 中最多删除一个字符所能得到的字典序最小的字符串。
输入输出样例
输入#1
3 aaa
输出#1
aa
输入#2
5 abcda
输出#2
abca
说明/提示
In the first example you can remove any character of s to obtain the string "aa".
In the second example "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda".
在第一个例子中,你可以删除 s 的任意一个字符来得到字符串 "aa"。
在第二个例子中,有 "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda"。
输入解题思路,AI测评打分。不知道怎么写?