B. Code Parsing

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with strings, 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 106characters. 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.

Sample test(s)
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".


解题说明:此题是字符串处理问题,针对一个仅包含x,y的字符串做两种操作,一个是交换x,y的位置,一个是同时删去x,y。最后要求输出删除所有x,y配对后剩下的串。这里注意到因为存在交换,故无论x,y的位置一开始是如何的,肯定能删除到只剩下一种字母的地步。此题转换为统计x,y的个数,判断谁多,输出相差的字符串即可。


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

int prime[110001];
int table[500][500];

int sieve()
{
	int count=0;
    long long int i,j;
    prime[count++]=2;
    for(i=3;i<110001;i+=2)
    {
        if(prime[i]==0)
        {
            prime[count++]=i;
            for(j=i*i;j<110001;j+=2*i)
            {
				prime[j]=1;
			}
        }
    }
	return count;
}

int main()
{
	char a[1000002];
	int i,x=0,y=0,d;
	scanf("%s",a);
	for(i=0;i<strlen(a);i++)
	{
		if(a[i]=='x')
		{
			x++;
		}
		else
		{
			y++;
		}
	}
	d=x-y;

	if(d>0)
	{
		while(d--)
		{
			printf("x");
		}
	}
	else
	{
		while(d++)
		{
			printf("y");
		}
	}
    return(0);
}


你可能感兴趣的:(B. Code Parsing)