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:
- 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.
- 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:
- 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.
- 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.
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.
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.
x
x
yxyxy
y
xxxxxy
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:
- string "yxyxy" transforms into string "xyyxy";
- string "xyyxy" transforms into string "xyxyy";
- string "xyxyy" transforms into string "xxyyy";
- string "xxyyy" transforms into string "xyy";
- 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=,c=;
int len=strlen(a);
for(int i=;i<len;i++)
if(a[i]=='x')
b++;
else c++;
if(b>c)for(int i=;i<=b-c;i++)cout<<'x';
else for(int i=;i<=c-b;i++)cout<<'y'; return ;
}
codeforce 225B Code Parsing的更多相关文章
- GCN code parsing
GCN code parsing 2018-07-18 20:39:11 utils.py --- load data def load_data(path="../data/cora/ ...
- Rewrite MSIL Code on the Fly with the .NET Framework Profiling API
http://clrprofiler.codeplex.com/ http://blogs.msdn.com/b/davbr/archive/2012/11/19/clrprofiler-4-5-re ...
- Codeforces Round #156 (Div. 2)
A. Greg's Workout 模3求和,算最大值. B. Code Parsing 最后左半部分为x,右半部分为y,那么从中间不断去掉xy,直到其中一种全部消去. C. Almost Arith ...
- eclipseGUI的可视化开发工具插件
一 各种GUI开发插件的特色 Eclipse并不自带GUI的可视化开发工具,那么如果要在Eclipse进行可视化的GUI开发,就需要依靠第三方的插件. 1. Visual Editor Eclip ...
- Dojo Style Guide
Contents: General Quick Reference Naming Conventions Specific Naming Conventions Files Variables Lay ...
- 浏览器详谈及其内部工作机制 —— web开发必读
浏览器介绍 如今,浏览器格局基本上是五分天下,分别是:IE.Firefox.Safari.Chrome.Opera,而浏览器引擎就更加集中了,主要是四大巨头:IE的浏览器排版引擎Trident,目前随 ...
- Awesome Go精选的Go框架,库和软件的精选清单.A curated list of awesome Go frameworks, libraries and software
Awesome Go financial support to Awesome Go A curated list of awesome Go frameworks, libraries a ...
- codeforce 421D D. Bug in Code
题目链接: http://codeforces.com/problemset/problem/421/D D. Bug in Code time limit per test 1 secondmemo ...
- (完全背包)Writing Code -- Codeforce 544C
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=99951#problem/C (zznu14) Writing Code Writin ...
随机推荐
- 世界疫情app柱形图显示
访问云服务器的mysql实现数据的获取.最后通过柱形图的形式将数据显示在页面上: 遇到的主要困难时对于云服务器的mysql连接本地的navicat之间事情,最后通过网上的各种解决办法完成了相关的内容. ...
- django实现自定义登陆验证
django实现自定义登陆验证 自定义装饰器函数和类 from utils.http import HttpResponseUnauthorized from django.views import ...
- 解决:docker-compose端口绑定
docker-compose 进程绑定 Bind for 0.0.0.0:3825 failed: port is already allocated 查看进程发现有进程在关闭后继续进行 docker ...
- mysql导出
--all-databases , -A 导出全部数据库. mysqldump -uroot -p --all-databases --all-tablespaces , -Y 导出全部表空间. my ...
- Python爬虫系列(四):Beautiful Soup解析HTML之把HTML转成Python对象
在前几篇文章,我们学会了如何获取html文档内容,就是从url下载网页.今天开始,我们将讨论如何将html转成python对象,用python代码对文档进行分析. (牛小妹在学校折腾了好几天,也没把h ...
- 一个hql 关键字member(非mysql)引起的 vo 数据 保存数据库错误
2015-03-19 14:16:29,285 ERROR [Thread-3] (DAOHelper.java:312) - updateByEntityPK:com.agileeagle.dao. ...
- c++ 启发式搜索解决八数码问题
本文对八数码问题 启发式搜索 (C++)做了一点点修改 //fn=gn+hn #include<iostream> #include<queue> #include<st ...
- L1-L11 jupter notebook 文件
L1-L11 jupter notebook 文件下载地址 https://download.csdn.net/download/xiuyu1860/12157961 包括L12 Transforme ...
- Mac os Pycharm 中使用Stanza进行实体识别(自然语言处理nlp)
stanza 是斯坦福开源Python版nlp库,对自然语言处理有好大的提升,具体好在哪里,官网里面都有介绍,这里就不翻译了.下面放上对应的官网和仓库地址. stanza 官网地址:点击我进入 sta ...
- [PHP]PHP设计模式:单例模式
单例模式(职责模式): 简单的说,一个对象(在学习设计模式之前,需要比较了解面向对象思想)只负责一个特定的任务: 单例类: 1.构造函数需要标记为private(访问控制:防止外部代码使用new操作符 ...