CodeForces - 255B Code Parsing (找规律简单)

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

Copy

y

input

xxxxxy

output

xxxx

题意就是 1如果y在x的前面就调换他们的顺序;

               2如果x在y的前面就删除这两个元素

     注意:步骤1要一直进行到不能进行才执行步骤2;

 

思路:其实这是一个找规律的题目,不难发现,不论你xy的位置怎么放,只要有x和y同时存在,最后一定会删除一个x和一个y

AC代码:

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	string s;
	int i,sy,sx;
	cin>>s;
	sx=sy=0;
	int len=s.length();
//	cout<<len<<endl;
	for(i=0;i<len;i++)
	{
		if(s[i]=='x') sx++;
		else 		  sy++;
	}
	int minn=min(sx,sy);
	 sx-=minn;
	 sy-=minn;
	if(sx>0)
	{
		for(i=1;i<=sx;i++)
		cout<<"x";
		cout<<endl;
	}
	else 
	{
		for(i=1;i<=sy;i++)
		cout<<"y";
		cout<<endl;
	}
	return 0;
 } 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值