Codeforces 797C - Minimal string
1 second
256 megabytes
standard input
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.
First line contains non-empty string s (1 ≤ |s| ≤ 105), consisting of lowercase English letters.
Print resulting string u.
cab
abc
acdb
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的更多相关文章
- CodeForces 797C Minimal string:贪心+模拟
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...
- Minimal string CodeForces - 797C
Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和u,每次操作可以将s的第一个字符取出并删除然后放到t的最后,或者将t的最后一个字符取出并删除然后放到u的 ...
- CodeForce-797C Minimal string(贪心模拟)
Minimal string CodeForces - 797C Petya 收到一个长度不超过 105 的字符串 s.他拿了两个额外的空字符串 t 和 u 并决定玩一个游戏.这个游戏有两种合法操作: ...
- CodeForces - 827A:String Reconstruction (基础并查集)
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...
- 【codeforces 797C】Minimal string
[题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...
- Minimal string CodeForces – 797C
题目链接 题目难度: 1700rating 题目类型:string+贪心+STL 题目思路: 由于题目要求的最终结果是字典序最小的那个字符串,那么我们从贪心的从’a’开始查找字符串里是否存在,如果存在 ...
- Codeforces 827E Rusty String - 快速傅里叶变换 - 暴力
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consist ...
- codeforces 825F F. String Compression dp+kmp找字符串的最小循环节
/** 题目:F. String Compression 链接:http://codeforces.com/problemset/problem/825/F 题意:压缩字符串后求最小长度. 思路: d ...
- Codeforces 946 C.String Transformation
C. String Transformation time limit per test 1 second memory limit per test 256 megabytes input st ...
随机推荐
- python类的组合
类的组合,即在类实例化时,将另一个类的实例作为参数传入,这样可以将两个实例关联起来. 当类之间有显著不同,并且较小的类是较大的类所需要的组件时,用组合比较好. 例如,描述一个机器人类,这个大类是由很多 ...
- rabbitmq heartbeat missing with heartbeat = N seconds原因总结
一直以来,在我们大规模使用rabbitmq的服务端应用中,都没有出现rabbitmq心跳超时而造成的的影响,反倒是在rabbitmq-cpp客户端出现过很多次该问题,一直以为客户端lib实现的问题(不 ...
- 03:git常见报错解决方法
1.1 git常见报错解决方法 1.warning: LF will be replaced by CRLF in .idea/workspace.xml. 参考博客:https://www.cnbl ...
- Linux限制普通用户只能使用某命令
修改sudoers(/etc/sudoers)
- opencv学习之路(15)、形态学其他操作(开、闭、顶帽、黑帽、形态学梯度)
一.形态学其他操作(用的不多,如果忘了也可以通过膨胀腐蚀得到相同效果) 1.开运算 2.闭运算 3.形态学梯度 4.顶帽 5.黑帽 #include "opencv2/opencv.hpp& ...
- 桌面版Ubuntu系统固定IP设置和Network-manager设置
我自己的学校是绑定MAC和IP上网的.这种方法名义上说是为了安全,不过是个搞计算机的都知道随便修改一下MAC就可以使用别人的IP了. 不提蛋疼的事情了,先来说说网络的配置吧 我用的是Ubuntu14. ...
- 【Python020--内嵌函数和闭包】
一.内嵌函数&闭包 1.最好是访问全局变量而不是修改全局变量,修改全局变量Python会内部屏蔽(修改后,函数会内部创建一个和全局变量一抹一样的变量) >>> count = ...
- 从0开始安装fedora23的笔记-- 以及使用fedora的常规问题-3
关于sys的目录有: /etc/sys/, 和 /proc/sys fedora的桌面背景图片默认的在: /usr/share/backgrounds/, 里面有f23, gnome, images等 ...
- Java lambda例子
简单数据类型int,跟Integer在lambda中的使用还不一样,有区别 code: package com.qhong.lambda.testDemo; import java.util.Arra ...
- POJ 2226 Muddy Fields(最小点覆盖)题解
题意:一片r*c的地,有些地方是泥地,需要铺地板.这些地板宽1,长无限,但只能铺在泥地上不能压到其他地方,问你铺满所有泥地最少几块 思路:我们把一行中连续的泥地看成整体,并把所有横的整体里的点编成一个 ...