Educational Codeforces Round 19 C. Minimal string
来源:互联网 发布:自学竹笛知乎 编辑:程序博客网 时间:2024/06/11 05:57
输入一个字符串,从左开始进行操作,每次可以把一个字母输出来,也可以把它放进一个栈里,可以随时取出输出,最终要求输出一个所有情况中的字典序最小的一种。
首先先记录一下每个字母的个数,方便动态的情况下找最小值,然后就开始遍历了,每次遍历找一下当前位置向右的所有字母的最小值如果这个值小于栈的最上面的字母就把这个字母放进栈内,否则就把栈里的最上面的输出,最后再把栈里的字母都输出即可。
#include<bits/stdc++.h>using namespace std;char s[100005],sta[100005],mi='a';int len,k=1;map<char,int>m;int main(){ cin>>s;len=strlen(s);sta[0]='z'+1; for(int i=0;i<len;i++)m[s[i]]++; for(int i=0;i<len;) { while(!m[mi])mi++; if(sta[k-1]>mi) { sta[k++]=s[i]; m[s[i]]--;i++; } else cout<<sta[--k]; } while(k!=1)cout<<sta[--k]; return 0;}
0 0
- Educational Codeforces Round 19 C. Minimal string
- Educational Codeforces Round 19 C. Minimal string
- Educational Codeforces Round 25 E. Minimal Labels
- Educational Codeforces Round 25 E. Minimal Labels
- Educational Codeforces Round 19 C题解
- Educational Codeforces Round 9 -- C - The Smallest String Concatenation
- Educational Codeforces Round 9 C The Smallest String Concatenation
- Educational Codeforces Round 9 C. The Smallest String Concatenation【思维】
- Educational Codeforces Round 25 E. Minimal Labels(拓扑排序)
- Educational Codeforces Round 25E. Minimal Labels(拓扑排序+思维)
- [拓扑序] Educational Codeforces Round 25 825E. Minimal Labels
- Educational Codeforces Round 21 C
- Educational Codeforces Round 5 C
- Educational Codeforces Round 26 C
- Codeforces 797C-Minimal string
- CodeForces 797C Minimal string
- codeforces Educational Codeforces Round 16-C
- Educational Codeforces Round 19 题解
- hdu1711 Number Sequence(KMP算法)
- 基于Hadoop生态圈的数据仓库实践 —— ETL
- 某地理位置模拟APP从壳流程分析到破解(劫持so过反调试)
- CDI初了解
- 40个Java多线程问题总结
- Educational Codeforces Round 19 C. Minimal string
- LeetCode 402 Remove K Digits 题解
- 解决Android Studio SVN传文件一直waiting for卡着不动
- 安装MYSQL碰到的问题
- 虚拟机复制遇到 Invalid UUID parameter ,问题解决方案
- json工具类
- Ceilometr: 5、Ceilometer安装和启动
- Knox & SEAndroid
- 初学Linux系统最应该做对的4件事情