题干:

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:

  1. 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.
  2. 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:

  1. 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.
  2. 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:

  1. string "yxyxy" transforms into string "xyyxy";
  2. string "xyyxy" transforms into string "xyxyy";
  3. string "xyxyy" transforms into string "xxyyy";
  4. string "xxyyy" transforms into string "xyy";
  5. 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".

题目大意:

给你一个字符串,定义两种操作:1.如果遇到相邻两字符是yx的情况,就交换两个字符串。2.如果遇到相邻两字符是xy的情况,就删除(remove)这两个字符。如果能操作1,就先操作1,如果整个字符串没有可操作字符,那么执行操作2。直到无法操作,输出此时的字符串。。。

解题报告:

这道题做的时候还是着急了、、直接就想着如果遇到了xy,那么就跳过。。。但是其实是不对的。。。仔细分析一下特征啊,从结果入手,,如果结果中有x和y,那么就一定还可以操作,,,因此最终一定是只有x或者只有y。那么究竟是哪一种呢?可以这么想啊,因为每一次remove操作都是去掉两个字符(一个x一个y),所以x和y都是成对删除的,,所以我们只需要看初始字符串哪个字符多就好了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 1e6 + 5;
char s[MAX];
int x,y;
int main()
{cin>>s;int len = strlen(s);for(int i = 0; i<len; i++) {if(s[i] == 'x') x++;if(s[i] == 'y') y++;}if(x > y) {for(int i = 1; i<=(x-y); i++) putchar('x');}else {for(int i = 1; i<=(y-x); i++) putchar('y');}return 0 ;}

错误代码:(WA10)(因为过不了  xxyy  这样的样例。)

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 1e6 + 5;
char s[MAX];
int main()
{cin>>s;int len = strlen(s);for(int i = 0; i<len; i++) {if(s[i] == 'y' && s[i+1] == 'x') {i++;continue;}if(s[i] == 'x' && s[i+1] == 'y') {i++;continue;}printf("%c",s[i]);}return 0 ;}

【CodeForces - 255B】Code Parsing(思维,字符串)相关推荐

  1. E - Code Parsing CodeForces - 255B(思维)

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

  2. 【CodeForces - 155C】Hometask (字符串,思维,贪心,熟悉句式)(总结)

    题干: Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the ...

  3. 【CodeForces】961 F. k-substrings 字符串哈希+二分

    [题目]F. k-substrings [题意]给定长度为n的串S,对于S的每个k-子串$s_ks_{k+1}...s_{n-k+1},k\in[1,\left \lceil \frac{n}{2} ...

  4. 【题解】 Codeforces Edu41 F. k-substrings (字符串Hash)

    题面戳我 Solution 我们正着每次都要枚举从长到短,时间复杂度承受不了,但是我们可以发现一个规律,假设某次的答案为\(x\),那么这个字符串为\(A+X+B\)组成,无论中间的\(X\)是重叠还 ...

  5. CodeForces - 1535C Unstable String(思维)

    题目链接:点击查看 题目大意:规定一个字符串将问号都替换成 000 或 111 后满足 010101 交替的话,该字符串是合法的,现在给出一个长度为 nnn 的字符串,求合法子串的个数 题目分析:两种 ...

  6. 2017-03-16 Codeforces 453A 概率期望,思维 UOJ 228(待补)

    Codeforces 453A    A. Little Pony and Expected Maximum 题意:一个m面质地均匀的骰子,每面出现的概率都是独立的1/m, 你需要投掷n次,其结果是这 ...

  7. Codeforces Zepto Code Rush 2014 -C - Dungeons and Candies

    这题给的一个教训:Codeforces没有超时这个概念.本来以为1000*(1000+1)/2*10*10要超时的.结果我想多了. 这题由于k层都可能有关系,所以建一个图,每两个点之间连边,边权为n* ...

  8. CodeForces - 768B Code For 1(找规律)

    题目链接:http://codeforces.com/problemset/problem/768/B点击打开链接 B. Code For 1 time limit per test 2 second ...

  9. CodeForces - 1593G Changing Brackets(思维)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的括号序列,其中包含了 {(,),[,]}\{(,),[,]\}{(,),[,]} 四种括号,现在可以进行两种操作: 将括号反转,代价为 000, ...

最新文章

  1. html根据文档定位,html文档中的location对象属性理解及常见的用法
  2. iask(http://ishare.iask.sina.com.cn/download/explain.php?fileid=12207500)
  3. Java this 关键字的用法
  4. with(nolock)简解
  5. 公有云 私有云 混合云_混合云的承诺,收益和产品
  6. 哪些人不能要 哪些人不能留
  7. QT之 Hello World
  8. 每个程序员都应该知道的5个定律
  9. (15)ZYNQ FPGA AXI-stream总线简介(学无止境)
  10. (转)KeyDown、KeyUp、KeyPress区别
  11. docker 容器连接宿主机mysql问题
  12. EvnetTimeWindow API
  13. android studio拟器,十二、安装Android Studio 模拟器
  14. kernel ramdump分析
  15. 视频加密技术的实与破解
  16. 中兴新支点操作系统_中兴新支点操作系统
  17. 精讲!!! Web服务器基础与http协议
  18. mysql navicat视图_navicat怎么创建视图
  19. CSS3 SVG实现可爱的动物哈士奇和狐狸动画
  20. 三类机构舆情-2019年3月5日

热门文章

  1. 轻松实现无刷新三级联动菜单[VS2005与AjaxPro]
  2. 【数据结构与算法】【算法思想】动态规划
  3. [Leetcode]第[58]题[JAVA][最后一个单词的长度][字符串]
  4. controller调用controller的方法_SpringCloud(5):Feign整合Ribbon和Hystrix来进行远程调用与服务熔断...
  5. Could NOT find XXX (missing: XXX_LIBRARY XXX_DIR)
  6. 获取场景中指定类的实例
  7. inside uboot (五) DRAM的构成
  8. 【OpenGL4.0】GLSL渲染语言入门与VBO、VAO使用:绘制一个三角形
  9. UE4 动态创建Actor并且附加static mesh
  10. Scrum之 Sprint计划会议