zoukankan      html  css  js  c++  java
  • codeforce 225B 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
    Copy
    x
    output
    Copy
    x
    input
    Copy
    yxyxy
    output
    Copy
    y
    input
    Copy
    xxxxxy
    output
    Copy
    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".

    #include<bits/stdc++.h>
    #define N 1000005
    using namespace std;
    typedef long long ll;
    char a[N];
    int main(){
        cin>>a;
        int b=0,c=0;
        int len=strlen(a);
        for(int i=0;i<len;i++)
            if(a[i]=='x')
                b++;
            else c++;
        if(b>c)for(int i=1;i<=b-c;i++)cout<<'x';
        else for(int i=1;i<=c-b;i++)cout<<'y';
    
        return 0;
    }
  • 相关阅读:
    Python爬虫入门教程 43-100 百思不得姐APP数据-手机APP爬虫部分
    也谈PostgreSQL的Vacuum机制及其最佳实践
    django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS
    Error: Invalid CSS after
    win32-x64-64inding.node is not a valid Win32 application
    Error: Module did not self-register
    数据分析|如何利用BI工具,探索各商品的潜在关联价值
    Python爬虫入门教程 42-100 爬取儿歌多多APP数据-手机APP爬虫部分
    Retrofit的文件上传和进度提示
    Retrofit的文件上传和进度提示
  • 原文地址:https://www.cnblogs.com/lunatic-talent/p/11386776.html
Copyright © 2011-2022 走看看