A. Minimizing the String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
ou are given a string ss consisting of nn 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…sns=s1s2…sn is lexicographically smaller than string t=t1t2…tmt=t1t2…tm if n<mn<m and s1=t1,s2=t2,…,sn=tns1=t1,s2=t2,…,sn=tn or n≥mn≥m and there exists a number pp such that p≤mp≤m and s1=t1,s2=t2,…,sp−1=tp−1s1=t1,s2=t2,…,sp−1=tp−1 and sp<tpsp<tp .
For example, "aaa" is smaller than "aaaa", "abb" is smaller than "abc", "pqr" is smaller than "z".
Input
The first line of the input contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105 ) — the length of ss .
The second line of the input contains exactly nn lowercase Latin letters — the string ss .
Output
Print one string — the smallest possible lexicographically string that can be obtained by removing at most one character from the string ss .
Examples
Input
3
aaa
Output
aa
Input
5
abcda
Output
abca
Note
In the first example you can remove any character of ss to obtain the string "aa".
In the second example "abca" < "abcd" < "abcda" < "abda" < "acda" < "bcda".
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
int k;
for(int t=0;t<n-1;t++)
{
if(s[t]>s[t+1])
{
k=t;
break;
}
}
for(int t=0;t<n;t++)
{
if(t==k)
{
continue;
}
cout<<s[t];
}
cout<<endl;
return 0;
}
A. Minimizing the String的更多相关文章
- Educational Codeforces Round 54 (Rated for Div. 2) Solution
A - Minimizing the String solved 题意:给出一个字符串,可以移掉最多一个字符,在所有可能性中选取一个字典序最小的. 思路:显然,一定可以移掉一个字符,如果移掉的字符的后 ...
- Educational Codeforces Round 54 (Rated for Div. 2) ABCD
A. Minimizing the String time limit per test 1 second memory limit per test 256 megabytes Descriptio ...
- codeforces1076 A.B.C.D.E
1076A 1076B 1076C 1076D 1076D A. Minimizing the String You are given a string s consisting of n low ...
- CoderForces Round54 (A~E)
ProblemA Minimizing the String 题目链接 题解:这一题读完题就写了吧.就是让你删除一个字母,使得剩下的字符组成的字符串的字典序最小:我们只要第一个当前位置的字符比下一个字 ...
- Codeforces Educational Codeforces Round 54 题解
题目链接:https://codeforc.es/contest/1076 A. Minimizing the String 题意:给出一个字符串,最多删掉一个字母,输出操作后字典序最小的字符串. 题 ...
- Codeforces Edu Round 54 A-E
A. Minimizing the String 很明显,贪心之比较从前往后第一个不一样的字符,所以可以从前往后考虑每一位,如果把它删除,他这一位就变成\(str[i + 1]\),所以只要\(str ...
- Codeforces Round #598 (Div. 3) D. Binary String Minimizing 贪心
D. Binary String Minimizing You are given a binary string of length n (i. e. a string consisting of ...
- Codeforces Round #598 (Div. 3) D. Binary String Minimizing
You are given a binary string of length nn (i. e. a string consisting of nn characters '0' and '1'). ...
- cf round 598div3 D.Binary String Minimizing
题目:https://codeforces.com/contest/1256/problem/D 题意:给你长度为n的01串,能将任意两相邻字符交换k次,求最小字典序的交换结果. 思路:贪心...甚至 ...
随机推荐
- [Python Study Notes]气泡散点图绘制
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ...
- CSS技巧: CSS隐藏文字的方法(CSS text-indent: -9999px;)
建站过过程中朋友喜欢把网站名称用H1表示,但从美观考虑,要用logo图片来代替h1,这时需要隐藏h1内的这段文字,但又不能对搜索引擎不友好,否则就失去了定义h1标签的意义. 在CSS中如何以图代字,找 ...
- HTML->CSS->JS->PHP的顺序及相关网址(转)
如果你有耐心坚持一年以上的话, 我会推荐HTML->CSS->JS->PHP的顺序来学习. 1. HTML学习:首先学习HTML,HTML作为标记语言是非常容易学的,把w3schoo ...
- Swing事件机制
-------------siwuxie095 Swing 是基于 MVC 结构的框架 在 Swing 中,所有的用户操作都是基于 Co ...
- 项目一:在线下单(补充) activeMQ使用(重点) 重构客户注册功能,发短信功能分离
1 课程计划 1.在线下单(补充) 2.activeMQ使用(重点) n 简介和安装 n activeMQ入门案例 n spring整合activeMQ应用 3.重构客户注册功能,发短信功能分离 n ...
- NSWindow上添加NSView
DBSCustomView *view = [[DBSCustomView alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]; [self.wi ...
- 多线程学习-基础( 十一)synchronized关键字修饰方法的简单案例
一.本案例设计到的知识点 (1)Object的notify(),notifyAll(),wait()等方法 (2)Thread的sleep(),interrupt(). (3)如何终止线程. (4)如 ...
- @RestControllerAdvice注解使用
在spring 3.2中,新增了@ControllerAdvice,@RestControllerAdvice 注解,可以用于定义@ExceptionHandler.@InitBinder.@Mode ...
- Android源码树中C代码的编译
侯 Sir说:“源码之下,了无秘密.” 但有些秘密还是要搞起来了看得更真切,仅从静态代码的体位很难体会到运动时的妙处.因此环境搭好了,下一步就是调试.gdbserver搭配gdb的调试环境走得很顺利, ...
- day05.3-Linux进程管理
1. 通过top指令可查看系统当前进程信息. 2. 通过free指令可查看系统内核信息.其中 free -m:以M为单位查看内核: free -h:以G为单位查 ...