• 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;
    }
  • 相关阅读:
    python3中的文件操作
    python3网络爬虫实现有道词典翻译功能
    C++11 thread condition_variable mutex 综合使用
    goland scope pattern 设置
    Go 1.11 Module 介绍
    hustOJ 添加 golang 支持
    docker 搭建 hustoj
    最长重复字符串题解 golang
    golang 结构体中的匿名接口
    使用aliyun cli工具快速创建云主机
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10782101.html
Copyright © 2020-2023  润新知