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<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
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<len;i++){if(s[i]=='x') a++;else b++;}int c=a-b;if(c>=0) {while(c--) cout<<'x';cout<<endl;}else{while(c++) cout<<'y';cout<<endl;}}
}

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

E - Code Parsing CodeForces - 255B(思维)相关推荐

  1. 【CodeForces - 255B】Code Parsing(思维,字符串)

    题干: Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vi ...

  2. CodeForces 798D 思维,贪心

    CodeForces 798D 题意:长度为 n的两个数组 a[]和 b[],要找出 k ( k<=n/2+1 )个下标,使得在两个数组中这 k个数的和乘上 2 要大于所有数的和. tags: ...

  3. Balanced Substring CodeForces - 873B (思维+前缀和)

    Balanced Substring CodeForces - 873B You are given a string s consisting only of characters 0 and 1. ...

  4. Levko and Permutation CodeForces - 361B 思维 数论

    题意 对一个长度,最大值为n的排列 构造出其恰好有k个GCD(i,a[i])>1 的排列 n<=1e5; 分析 由于每个大于1的数与自己的gcd必然>1 所以构造大于1的gcd可以用 ...

  5. codeforces - 1315C - 思维题

    原题链接:https://codeforces.com/problemset/problem/1315/C 翻译: 这是一个猜谜游戏,你需要猜中一个序列,谜题是一个序列,我们设为b,长度为n.你需要根 ...

  6. Codeforces 1093C (思维+贪心)

    题面 传送门 题目大意: 有一个长n(n为偶数)的序列a 已知a满足 \(a_1≤a_2≤⋯≤a_n\) 给出一个长度为\(\frac{n}{2}\) 的序列b,定义\(b_i=a_i+a_{n-i+ ...

  7. B. Bogosort codeforces(思维)

    outputstandard output You are given an array a1,a2,-,an. Array is good if for each pair of indexes i ...

  8. Count Subrectangles CodeForces - 1323B(思维)

    You are given an array a of length n and array b of length m both consisting of only integers 0 and ...

  9. Dead Pixel CodeForces - 1315A(思维)

    Screen resolution of Polycarp's monitor is a×b pixels. Unfortunately, there is one dead pixel at his ...

最新文章

  1. CSS里面position:relative与position:absolute 区别
  2. Beyond Compare进行内容替换的方法有哪些
  3. c 调用易语言dll字节集,总结VC与易语言DLL互相调用的方法
  4. springboot mybatis 热加载mapper.xml文件(最简单)
  5. ScriptManager和ClientScriptManager
  6. Linux基础命令---tracepath
  7. 微服务springCloud初识
  8. full gc 次数_32. GC 是怎样工作的?
  9. 数据结构_C语言_实验二_树 ——还原二叉树
  10. CSDN 博客 美化 个性化
  11. TLS协议簇加解密流程
  12. 上海航芯|推出基于ACX200T的V2X解决方案
  13. 微信小程序之实现到商品列表跳转商品详情页
  14. 椭圆隐式方程和参数方程的互相转换
  15. 彻底认清PHP单例模式
  16. 熟悉FreeSWITCH 一
  17. Kafka 3.1的KRaft模式里的broker与controller
  18. 教师资格证考试科目汇总
  19. 中文正则字符大全集2
  20. Unity3D 显示FPS的脚本

热门文章

  1. 制作旋转led_LED用蓝宝石衬底及加工工艺!
  2. python3.7官网中文官网_通用操作系统服务
  3. vue脚手架依赖包安装不成功_Windows下vue-cli的搭建
  4. Android开发之引用三方库导致SO库冲突的解决办法
  5. 分析Android studio3.0的instant run开启关闭对APK大小的影响
  6. 能使曲线变平滑的一维滤波器_双边滤波器的原理及实现
  7. 6月19日 NSFileHandle文件类的常用方法
  8. 255.255.255.255代表什么_LCD 党的真香警告?最近各家炒得很火的 DC 和 PWM 调光是什么鬼...
  9. java lock代码写法_java Lock接口详解及实例代码
  10. 硬链接与软链接的区别