CF797C.Minimal string

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves:

  • Extract the first character of s and append t with this character.
  • Extract the last character of t and append u with this character.

Petya wants to get strings s and t empty and string u lexicographically minimal.

You should write a program that will help Petya win the game.

佩佳生日时收到了一份礼物:一个长度最多为 10510^5 的字符串 ss。他另外准备了两个空字符串 tt 和 uu,并决定玩一个游戏。该游戏有两种可能的操作:

  • 取出 ss 的第一个字符,并将其追加到 tt 的末尾;
  • 取出 tt 的最后一个字符,并将其追加到 uu 的末尾。

佩佳希望最终使字符串 ss 和 tt 均为空,且字符串 uu 的字典序尽可能小。

你需要编写一个程序,帮助佩佳赢得这个游戏。

输入格式

First line contains non-empty string s (1 ≤ |s| ≤ 105), consisting of lowercase English letters.

第一行包含一个非空字符串 ss(1 ≤ ∣s∣ ≤ 1051 \leq |s| \leq 10^5),由小写英文字母组成。

输出格式

Print resulting string u.

输出结果字符串 uu。

输入输出样例

  • 输入#1

    cab

    输出#1

    abc
  • 输入#2

    acdb

    输出#2

    abdc

输入解题思路,AI测评打分。不知道怎么写?

首页