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 ...
随机推荐
- XX-net
环境:win10企业版 #停用“ip helper”服务 net stop "ip helper" #启用“ip helper”服务 net start "ip help ...
- Mac下Homebrew的安装与使用
Homebrew简介,安装与使用 简介 Homebrew 官方网站 Homebrew是一个包管理器,用于安装Apple没有预装但你需要的UNIX工具.(比如著名的wget). Homebrew会将软件 ...
- Python 使用 face_recognition 人脸识别
Python 使用 face_recognition 人脸识别 官方说明:https://face-recognition.readthedocs.io/en/latest/readme.html 人 ...
- k8s debug
https://feisky.gitbooks.io/kubernetes/components/api-aggregation.html API convention Kubernetes deep ...
- linux 实时显示网速bash
执行方法先授权再运行 chmod +x shi.sh脚本+网卡名称 ./shi.sh ens33 #!/bin/bash while [ "1" ] do eth=$1 RXpre ...
- php 操作 mysql 数据库常用方法集合
参考: https://www.runoob.com/php/php-pdo.html https://www.cnblogs.com/feng18/p/6523646.html https://bl ...
- GDPR
http://column.caijing.com.cn/20180523/4457753.shtml
- java利用poi解析excel文件
首先需要引入以下jar包 如果使用maven,需要添加两个依赖 <dependencies> <dependency> <groupId>org.apache.po ...
- 配置named服务之前的 相关术语意思
putty: [p^ti]: 油灰, 腻子,像 clay 粘土一样起 连接作用. 非常简洁,只有500多kB, 不需要安装,纯绿色的,版本还是0.x, Simon Tatham, 甚至没有主界面,没有 ...
- js实现刷新iframe的方法汇总
https://www.jb51.net/article/65013.htm javascript实现刷新iframe的方法的总结,现在假设存在下面这样一个iframe,则刷新该iframe的N种方法 ...