CF255B.Code Parsing

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

小 Vitaly 喜欢各种算法。今天他专门为你们发明了一种新算法。Vitaly 的算法作用于由字符 "x" 和 "y" 组成的字符串 ss,并在运行过程中使用以下两种操作:

  1. 在字符串中寻找两个连续的字符,使得第一个字符为 "y",第二个字符为 "x",然后交换它们的位置。若存在多个满足条件的字符对,则选择在字符串中位置更靠前(即下标更小)的一对。
  2. 在字符串中寻找两个连续的字符,使得第一个字符为 "x",第二个字符为 "y",然后将这两个字符从字符串中删除。若存在多个满足条件的字符对,则选择在字符串中位置更靠前(即下标更小)的一对。

该新算法的输入为字符串 ss,其执行流程如下:

  1. 若字符串可执行上述任一操作,则进入算法的第 2 步;否则,停止执行算法,并输出当前字符串。
  2. 若可执行操作 1,则执行操作 1;否则,执行操作 2。执行完操作后,返回算法的第 1 步。

现在 Vitaly 想知道:若算法的输入为字符串 ss,最终输出的结果是什么?

输入格式

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.

第一行包含一个非空字符串 ss。

保证该字符串仅由字符 "x" 和 "y" 组成。
保证该字符串长度至多为 10610^6 个字符。
保证算法执行结果不会是空字符串。

输出格式

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.

在唯一的一行中输出算法执行后打印的字符串,其中算法的输入为字符串 ss。

输入输出样例

  • 输入#1

    x

    输出#1

    x
  • 输入#2

    yxyxy

    输出#2

    y
  • 输入#3

    xxxxxy

    输出#3

    xxxx

说明/提示

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. 字符串 “yxyxy” 变换为字符串 “xyyxy”;
  2. 字符串 “xyyxy” 变换为字符串 “xyxyy”;
  3. 字符串 “xyxyy” 变换为字符串 “xxyyy”;
  4. 字符串 “xxyyy” 变换为字符串 “xyy”;
  5. 字符串 “xyy” 变换为字符串 “y”。

最终,我们得到字符串 “y”。

在第三个测试用例中,仅发生一次变换:字符串 “xxxxxy” 变换为字符串 “xxxx”。因此,答案为字符串 “xxxx”。

输入解题思路,AI测评打分。不知道怎么写?

首页