zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    awk去重以某列重复的行
    awk 统计文件中按照某列统计某列的和(sum)
    使用jdk压缩war包
    histoty显示时间戳
    awk统计文件中某关键词出现次数
    Jbox帮助文档,默认的属性含义
    net之session漫谈及分布式session解决方案
    StackExchange.Redis 基本使用 (一) (转)
    Sql Server 表创建以及Ef浅谈
    数据验证(自定义特性)
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10782101.html
Copyright © 2011-2022 走看看