Two Operations Gym - 102263M

Ayoub has a string SS consists of only lower case Latin letters, and he wants you to make some operations on it:

  1. you can swap any two characters in the string.
  2. you can delete any two adjacent characters that have the same value and replace them with the next character alphabetically,for example string "abbx""abbx" could be "acx""acx" after one operation, string "zz""zz" could not be changed; because z is the last character in the English alphabets.

Ayoub wants you to make the string lexicographically maximal using the mentioned operations as many times as you want, can you help him?

String x=x1x2...x|x|x=x1x2...x|x| is lexicographically larger than string y=y1y2...y|y|y=y1y2...y|y|, if either |x|>|y||x|>|y| and x1=y1,x2=y2,...,x|y|=y|y|x1=y1,x2=y2,...,x|y|=y|y|, or exists such number r(r<|x|,r<|y|)r(r<|x|,r<|y|), that x1=y1,x2=y2,...,xr=yrx1=y1,x2=y2,...,xr=yr and xr+1>yr+1xr+1>yr+1. Characters in lines are compared like their ASCII codes.

Input

  The input contains a single string SS (1≤|S|≤105)(1≤|S|≤105).

  It is guaranteed that string SS consists of only lower case Latin letters.

Output

  print the lexicographically maximal string that could be obtained using these two operations.

#include<algorithm>
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std; priority_queue <char, vector<char>, greater<char> >q1;//从小到大优先排序
priority_queue <char, vector<char>, less<char> >q2;//从大到小优先排序
int main()
{
string s;
cin >> s;
for (int i = ; i < s.size(); i++) {
q1.push(s[i]);
}
while (!q1.empty()) {
char top = q1.top();//获取栈顶
q1.pop();
if (!q1.empty() && top != 'z') {
if (top == q1.top()) {//合并插入
q1.pop();
q1.push(top + );
}
else {
q2.push(top);
}
}
else {
q2.push(top);
}
}
while (!q2.empty()) {
char head = q2.top();
q2.pop();
cout << head;
}
return ;
}

Two Operations Gym - 102263M 优先队列水题的更多相关文章

  1. Codeforces Gym 100531G Grave 水题

    Problem G. Grave 题目连接: http://codeforces.com/gym/100531/attachments Description Gerard develops a Ha ...

  2. UVaLive 6591 && Gym 100299L Bus (水题)

    题意:略. 析:不解释,水题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include < ...

  3. Codeforces Gym 100286I iSharp 水题

    Problem I. iSharpTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/ ...

  4. CodeForces Gym 100685C Cinderella (水题)

    题意:给定 n 个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子. 析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要 ...

  5. Argus UVALive - 3135(优先队列 水题一道)

    有一系列的事件,它每Period秒钟就会产生编号为qNum的事件,你的任务是模拟出前k个事件,如果多个事件同时发生,先处理qNum小的事件 今天再看看数据结构.. #include <iostr ...

  6. Gym 100531G Grave(水题)

    题意:给定一个大矩形,再给定在一个小矩形,然后给定一个新矩形的长和高,问你能不能把这个新矩形放到大矩形里,并且不与小矩形相交. 析:直接判定小矩形的上下左右四个方向,能不能即可. 代码如下: #pra ...

  7. codeforces Gym 100187L L. Ministry of Truth 水题

    L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  8. 水题 Gym 100553K Knockout Racing

    题目传送门 /* 题意:有若干个点在一个区间内来回移动,1m/s. 水题:n^2的复杂度能解决,注意时间可能大于一个周期,要取模 */ #include <cstdio> #include ...

  9. Codeforces Gym 100286G Giant Screen 水题

    Problem G.Giant ScreenTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/con ...

随机推荐

  1. 史上最详细的VM虚拟机安装Kali-linux教程(以2020.1版本为例,含下载地址+默认提升为root权限)

    一.官方下载 Kali Linux 官方网址:www.Kali.org下载方式分两种:http 下载和 bt 下载(由于是国外网站 http 方式下载会非常慢),选择对应版本点击即可下载. 二.创建新 ...

  2. 详解 Arrays类

    请关注本人博文--<详解 普通数组 -- Arrays类 与 浅克隆> Arrays类: 概述: 针对数组进行操作的工具类.它提供了对于数组的值的排序.查找等功能. 现在,本人来展示一下A ...

  3. 详解 Collections类

    (请关注 本人"集合总集篇"博文--<详解 集合框架>) 有的同学可能会有这样的疑问 -- Collections类也是集合吗? 答曰:非也! 那为什么要讲解这个类呢? ...

  4. C# 基础知识系列- 12 任务和多线程

    0. 前言 照例一份前言,在介绍任务和多线程之前,先介绍一下异步和同步的概念.我们之间介绍的知识点都是在同步执行,所谓的同步就是一行代码一行代码的执行,就像是我们日常乘坐地铁通过安检通道一样,想象我们 ...

  5. 2019-2020-1 20199325《Linux内核原理与分析》第八周作业

    Linux内核如何装载和启动一个可执行程序 1.理解编译链接的过程和ELF可执行文件格式,详细内容参考本周第一节:​ 2.编程使用exec*库函数加载一个可执行文件,动态链接分为可执行程序装载时动态链 ...

  6. 设计模式 - 迭代器模式详解及其在ArrayList中的应用

    基本介绍 迭代器模式(Iterator Pattern)是 Java 中使用最多的一种模式,它可以顺序的访问容器中的元素,但不需要知道容器的内部细节 模式结构 Iterator(抽象迭代器):定义遍历 ...

  7. js 实现文字滚动功能,可更改配置参数 带完整版解析代码。

    前言:         本人纯小白一个,有很多地方理解的没有各位大牛那么透彻,如有错误,请各位大牛指出斧正!小弟感激不尽.         本篇文章为您分析一下原生JS写文字滚动效果 需求分析: 需要 ...

  8. 【集群实战】Rsync试题-异机数据备份解决方案

    企业案例:Rsync上机实战考试题: 某公司有一台Web服务器,里面的数据很重要,但是如果硬盘坏了,数据就会丢失,现在领导要求你把数据在其它机器上做一个周期性定时备份. 要求如下: 每天晚上00点整在 ...

  9. 从蓝瘦“想哭”到 SELinux 看操作系统安全何在

    最近一周,来自网络的"想哭"勒索病毒(Wannacry Ransomware)在世界各地同时上演了一部绑匪大片,台词华丽,演技出色,当仁不让地新晋世界第一网红.全球各国除了默默忙于 ...

  10. 更改 vsftpd 的端口号

    2019独角兽企业重金招聘Python工程师标准>>> vsftpd启动后,默认的ftp端口是21,现在我想把ftp端口改成 801 ,修改后能保证用户上传下载不受影响 1.编辑 / ...