Educational Codeforces Round 19 C
Description
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 <bits/stdc++.h>
using namespace std;
int num[];
string s;
int check(char c)
{
for(int i='a';i<c;i++)
{
if(num[i])
{
return ;
}
}
return ;
}
stack<char>q;
int main() {
ios::sync_with_stdio(false);
cin.tie();
cin>>s;
for(int i=;i<s.size();i++)
{
num[s[i]]++;
}
int cnt=;
while(cnt<s.size())
{
if(q.empty())
{
q.push(s[cnt]);
num[s[cnt]]--;
cnt++;
}
else if(check(q.top()))
{
cout<<q.top();
q.pop();
}
else
{
q.push(s[cnt]);
num[s[cnt]]--;
cnt++;
}
}
while(!q.empty())
{
cout<<q.top();
q.pop();
}
return ;
}
Educational Codeforces Round 19 C的更多相关文章
- Educational Codeforces Round 19 A, B, C, E(xjb)
题目链接:http://codeforces.com/contest/797 A题 题意:给出两个数n, k,问能不能将n分解成k个因子相乘的形式,不能输出-1,能则输出其因子: 思路:将n质因分解, ...
- Educational Codeforces Round 19
A. k-Factorization 题目大意:给一个数n,求k个大于1的数,乘积为n.(n<=100,000,k<=20) 思路:分解质因数呗 #include<cstdio> ...
- Educational Codeforces Round 19 题解【ABCDE】
A. k-Factorization 题意:给你一个n,问你这个数能否分割成k个大于1的数的乘积. 题解:因为n的取值范围很小,所以感觉dfs应该不会有很多种可能-- #include<bits ...
- 【Educational Codeforces Round 19】
这场edu蛮简单的…… 连道数据结构题都没有…… A.随便质因数分解凑一下即可. #include<bits/stdc++.h> #define N 100005 using namesp ...
- Educational Codeforces Round 19 A+B+C+E!
A. k-Factorization 题意:将n分解成k个大于1的数相乘的形式.如果无法分解输出-1. 思路:先打个素因子表,然后暴力判,注意最后跳出的条件. int len,a[N],b[N]; v ...
- Educational Codeforces Round 19 B
Description You are given sequence a1, a2, ..., an of integer numbers of length n. Your task is to f ...
- Educational Codeforces Round 19 A
Description Given a positive integer n, find k integers (not necessary distinct) such that all these ...
- Educational Codeforces Round 19 E. Array Queries(暴力)(DP)
传送门 题意 给出n个数,q个询问,每个询问有两个数p,k,询问p+k+a[p]操作几次后超过n 分析 分块处理,在k<sqrt(n)时,用dp,大于sqrt(n)用暴力 trick 代码 #i ...
- Educational Codeforces Round 17
Educational Codeforces Round 17 A. k-th divisor 水题,把所有因子找出来排序然后找第\(k\)大 view code //#pragma GCC opti ...
随机推荐
- Service Mesh vs SideCar
Istio = 微服务框架 + 服务治理 Istio 大幅降低微服务架构下应用程序的开发难度,势必极大的推动微服务的普及.个人乐观估计,随着isito的成熟,微服务开发领域将迎来一次颠覆性的变革.后面 ...
- mysql order by的一些技巧
1. 只按日期排序,忽略年份> select date, description from table_name order by month(date),dayofmonth(date);注意 ...
- unity 3D Mesh网络模型,怎样将Constructer拖入场景??
下图中的将Constructer拖入场景,怎么拖入,不知道... 1.Constructer是一个什么东西?在 下图中没有看到这个名字的,于是乎,我就不知道该怎么办了...
- Phoenix(SQL On HBase)安装和使用报告
一.为什么使用Phoenix二.安装Phoenix2.1 兼容问题?2.2 编译CDH版本的Phoenix2.3 安装Phoenix到CDH环境中三.Phoenix的使用3.1 phoenix的4种调 ...
- Mongoose Embedded Web Server Library
https://github.com/cesanta/mongoose http://ltp.ai/docs/ltpserver.html LTP Server在轻量级服务器程序mongoose基础上 ...
- linux 解决 Device eth0 does not seem to be present
在虚拟机中安装cent os系统,然后配置网络 执行命令ifconfig 没有看到eth0的信息: 重启网卡报错: service network restart Shutting down loop ...
- Java 快速失败( fail-fast ) 安全失败( fail-safe )
原文:http://www.cnblogs.com/ygj0930/p/6543350.html 快速失败( fail-fast ):当你在迭代一个集合的时候,如果有另一个线程正在修改你正在访问的那个 ...
- Linux:外网域名防火墙设置导致下载失败
问题现象: 通过IE从服务器下载文件时,提示Can't read from connection: Connection reset by peer. 别的现场都是好的,只有该现场有这个问题.所以,一 ...
- 安装程序工具 (Installutil.exe)22
网址:https://msdn.microsoft.com/zh-cn/library/50614e95(VS.80).aspx 安装程序工具 (Installutil.exe) .NET Fram ...
- BZOJ_5311_贞鱼_决策单调性+带权二分
BZOJ_5311_贞鱼_决策单调性+带权二分 Description 众所周知,贞鱼是一种高智商水生动物.不过他们到了陆地上智商会减半. 这不?他们遇到了大麻烦! n只贞鱼到陆地上乘车,现在有k辆汽 ...