C. Minimal string
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 lexigraphically minimal.

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

Input

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

Output

Print resulting string u.

Examples
input
cab
output
abc
input
acdb
output
abdc
题目大意:略。
方法:栈顶的优先级大于后缀的优先级,则出栈。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
const int N=1e5+;
int main()
{
char s[N];
gets(s);
int n=strlen(s);
char best[N];
best[n]='z';
for(int i=n-;i>=;i--)
{
best[i]=min(best[i+],s[i]);
}
stack<char>v;
int cur=;
while(!v.empty()||cur<n)
{
if(!v.empty()&&v.top()<=best[cur])
{
putchar(v.top());
v.pop();
}
else v.push(s[cur++]);
}
cout<<endl;
return ;
}

Codeforces 797C - Minimal string的更多相关文章

  1. CodeForces 797C Minimal string:贪心+模拟

    题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...

  2. Minimal string CodeForces - 797C

    Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和u,每次操作可以将s的第一个字符取出并删除然后放到t的最后,或者将t的最后一个字符取出并删除然后放到u的 ...

  3. CodeForce-797C Minimal string(贪心模拟)

    Minimal string CodeForces - 797C Petya 收到一个长度不超过 105 的字符串 s.他拿了两个额外的空字符串 t 和 u 并决定玩一个游戏.这个游戏有两种合法操作: ...

  4. CodeForces - 827A:String Reconstruction (基础并查集)

    Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...

  5. 【codeforces 797C】Minimal string

    [题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...

  6. Minimal string CodeForces – 797C

    题目链接 题目难度: 1700rating 题目类型:string+贪心+STL 题目思路: 由于题目要求的最终结果是字典序最小的那个字符串,那么我们从贪心的从’a’开始查找字符串里是否存在,如果存在 ...

  7. Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力

    Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...

  8. codeforces 825F F. String Compression dp+kmp找字符串的最小循环节

    /** 题目:F. String Compression 链接:http://codeforces.com/problemset/problem/825/F 题意:压缩字符串后求最小长度. 思路: d ...

  9. Codeforces 946 C.String Transformation

    C. String Transformation   time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. 汇编语言教材assembly language

    https://en.wikipedia.org/wiki/Assembly_language https://baike.baidu.com/item/%E6%B1%87%E7%BC%96%E8%A ...

  2. SQLServer和MySql的区别总结

    SqlServer支持like '%'+'87'+'%' 拼接字符串  但MySql里不支持,只能用CONCAT('%','87','%')拼接,否则异常 1.递归函数的区别类别表CREATE TAB ...

  3. Android图片裁剪解决方案 -- 从相册截图

    在看Storage Access Framework,里面有一个加载相册图片的程序片断,可能是系统版本的问题,无法返回结果,这里找到一个适用于旧版本的方法. 在Android开发中,可以轻松调用一个I ...

  4. kali linux 64bit 2019.1a下启动bbqsql:No module named coros

    kali linux 64bit 2019.1a下bbqsql启动失败,错误: File "/usr/local/lib/python2.7/dist-packages/bbqsql/lib ...

  5. CEF 添加F5刷新快捷键

    Keyboardcodes:https://www.androidos.net.cn/android/4.3_r1/xref/external/webkit/Source/WebCore/platfo ...

  6. linux --- 3 vim 网络 用户 权限 软连接 压缩 定时任务 yum源

    一.vi 和vim vi 是老式的字处理器,不过功能已经很齐全了,但是还是有可以进步的地方. vim 则可以说是程序开发者的一项很好用的工具 ①命令模式 移动光标 w(e) 移动光标到下一个单词 b ...

  7. Ubuntu18.04 一些好用的扩展

    原文:https://www.lulinux.com/archives/2589 一些好用的扩展: United:https://www.gnome-look.org/p/1167950/ dynam ...

  8. CentOS7.2 问题收集 查看文件大小 查看端口

    1.在vmware中使用nat模式安装centos7.2,没有ifconfig命令? yum upgrade yum install net-tools 2.查看当前目录所有文件大小 [root@lo ...

  9. sudo用法记录

    使用root用户,visudo命令(实际是编辑/etc/sudoers文件),用法和vim一样,末行模式:wq退出,如还有提示,使用大写"Q"保存退出,小写"e" ...

  10. (转) 机器学习很有趣Part6:怎样使用深度学习进行语音识别

    本文转自:http://www.jiqizhixin.com/article/2321 机器学习很有趣Part6:怎样使用深度学习进行语音识别 2017-02-19 13:20:47    机器学习  ...