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 ...
随机推荐
- setUp() and setUpBeforeClass()
The @BeforeClass and @AfterClass annotated methods will be run exactly once during your test run - a ...
- Android Menu开源项目整合工程
本实例整合了关于Android Menu的优秀开源代码,方便有需要用到Menu开源项目的小伙伴使用. 一.整合的项目有: SlidingMenu:https://github.com/jfeinste ...
- Python开发【2.2 异常处理】
1.Python常见异常类型: Exception 常规错误的基类 AttributeError 对象没有这个属性 IOError 输入/输出操作失败 IndexError 序列中没有此索引(inde ...
- ORA-01031: insufficient privileges 解决办法
sysdba不能远程登录这个也是一个很常见的问题了. 碰到这样的问题我们该如何解决呢? 我们用sysdba登录的时候,用来管理我们的数据库实例,特别是有时候,服务器不再本台机器,这个就更是有必要了. ...
- (25) java web的struts2框架的使用-基于表单的文件上传
一,首先创建一个表单页面 <body> <form action="uploads" method="post" enctype=" ...
- maven安装的详细步骤
1.下载maven的bin,在apache官方网站下载.window系统下的下载红色方框的 2.解压后, 把bin的位置设在环境变量里,新建环境变量 MAVEN_HOME.这个配置是方便以后更换mav ...
- I.MX6 按键开关机 PMIC 检测
/************************************************************************* * I.MX6 按键开关机 PMIC 检测 * 说 ...
- Ubuntu bitnami gitlab 安装
/************************************************************************************** * Ubuntu bit ...
- 传统开发有必要学Dubbo吗
dubbo作为一个知名的分布式服务调用框架,在众多互联网公司都有广泛的应用.但其本质还是一个远程服务调用框架,最初就是为了应对SOA服务治理时才用到的,如果本身服务不多就没必要用它了.如果对技术感兴趣 ...
- bzoj1084 [SCOI2005]最大子矩阵——背包
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1084 水题...分类讨论一下即可. 代码如下: #include<iostream&g ...