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. mycat下mysql jdbc connector使用高版本报PacketTooBigException异常

    如下所示: 5.1.30切换为mysql-connector 5.1.46/40,报错,可参考https://blog.csdn.net/n447194252/article/details/7530 ...

  2. android之发送Get或Post请求至服务器接口

    import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.IOException; imp ...

  3. 在用网站ICP备案主体变更导致网站无法访问问题解决

    关于ICP备案: 备案的目的:是为了防止在网上从事非法的网站经营活动,打击不良互联网信息的传播,如果网站不备案的话,很有可能被查处以后关停.非经营性网站自主备案是不收任何手续费的,所以建议大家可以自行 ...

  4. opencv学习之路(3)、批量读取图片、视频分解、视频合成

    一.批量有序读取图片 #include<opencv2/opencv.hpp> using namespace cv; void main() { //批量读取图片(有序) ]; ]; M ...

  5. 使用liner、feather、multiband对已经拼接的数据进行融合(下)

    理解mulitband.所谓的mulitband,其实就是一种多尺度的样条融合,其实现的主要方法就是laplace金字塔. 高斯金字塔是向下采样,而laplace金字塔式向上采样(也就是恢复),采用的 ...

  6. Codeforces 789D Weird journey - 欧拉路 - 图论

    Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his mot ...

  7. win7记事本txt图标显示异常解决方法

    链接:https://zhidao.baidu.com/question/2076205353435701108.html                                       ...

  8. JPush Flutter Plugin(Futter推送-极光推送)

    https://pub.flutter-io.cn/packages/jpush_flutter JPush's officially supported Flutter plugin (Androi ...

  9. 2-sat相关复习

    2-sat相关复习 noi曾经考过,谁能说得准呢 sat问题 通俗的sat问题表述一般是这样的:有很多个集合,每个集合里面有若干元素,现给出一些取元素的规则,要你判断是否可行,可行则给出一个可行方案. ...

  10. P1552 [APIO2012]派遣

    链接 https://www.luogu.org/problemnew/show/P1552 思路 忍者数量肯定越多越好 那就从下到上的合并它的孩子 左偏树的话 顺便维护一个tot,大头堆,如果tot ...