博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
E - Code Parsing CodeForces - 255B(思维)
阅读量:4136 次
发布时间:2019-05-25

本文共 2828 字,大约阅读时间需要 9 分钟。

Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly’s algorithm works with string s, consisting of characters “x” and “y”, and uses two following operations at runtime:

Find two consecutive characters in the string, such that the first of them equals “y”, and the second one equals “x” and swap them. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string.

Find in the string two consecutive characters, such that the first of them equals “x” and the second one equals “y”. Remove these characters from the string. If there are several suitable pairs of characters, we choose the pair of characters that is located closer to the beginning of the string.
The input for the new algorithm is string s, and the algorithm works as follows:

If you can apply at least one of the described operations to the string, go to step 2 of the algorithm. Otherwise, stop executing the algorithm and print the current string.

If you can apply operation 1, then apply it. Otherwise, apply operation 2. After you apply the operation, go to step 1 of the algorithm.
Now Vitaly wonders, what is going to be printed as the result of the algorithm’s work, if the input receives string s.

Input

The first line contains a non-empty string s.

It is guaranteed that the string only consists of characters “x” and “y”. It is guaranteed that the string consists of at most 106 characters. It is guaranteed that as the result of the algorithm’s execution won’t be an empty string.

Output

In the only line print the string that is printed as the result of the algorithm’s work, if the input of the algorithm input receives string s.

Examples

Input
x
Output
x
Input
yxyxy
Output
y
Input
xxxxxy
Output
xxxx
Note
In the first test the algorithm will end after the first step of the algorithm, as it is impossible to apply any operation. Thus, the string won’t change.

In the second test the transformation will be like this:

string “yxyxy” transforms into string “xyyxy”;

string “xyyxy” transforms into string “xyxyy”;
string “xyxyy” transforms into string “xxyyy”;
string “xxyyy” transforms into string “xyy”;
string “xyy” transforms into string “y”.
As a result, we’ve got string “y”.

In the third test case only one transformation will take place: string “xxxxxy” transforms into string “xxxx”. Thus, the answer will be string “xxxx”.

一个模拟题目,但是如果真的正儿八经的模拟肯定会超时。仔细想想到了最后,剩下的字母就是谁多就剩下谁,O(n)的复杂度,代码如下:

#include
#include
#include
#include
#include
using namespace std;const int maxx=1e6+10;char s[maxx];int main(){ while(scanf("%s",s)!=EOF) { int len=strlen(s); int a=0; int b=0; for(int i=0;i
=0) { while(c--) cout<<'x';cout<

努力加油a啊,(o)/~

转载地址:http://wkxvi.baihongyu.com/

你可能感兴趣的文章
collect2: ld returned 1 exit status
查看>>
C#入门
查看>>
C#中ColorDialog需点两次确定才会退出的问题
查看>>
数据库
查看>>
nginx反代 499 502 bad gateway 和timeout
查看>>
linux虚拟机安装tar.gz版jdk步骤详解
查看>>
python实现100以内自然数之和,偶数之和
查看>>
python数字逆序输出及多个print输出在同一行
查看>>
苏宁产品经理面经
查看>>
百度产品经理群面
查看>>
去哪儿一面+平安科技二面+hr面+贝贝一面+二面产品面经
查看>>
element ui 弹窗在IE11中关闭时闪现问题修复
查看>>
vue 遍历对象并动态绑定在下拉列表中
查看>>
Vue动态生成el-checkbox点击无法选中的解决方法
查看>>
python __future__
查看>>
MySQL Tricks1
查看>>
python 变量作用域问题(经典坑)
查看>>
pytorch
查看>>
pytorch(三)
查看>>
ubuntu相关
查看>>