hdu B. Code Parsing
来源:互联网 发布:three.js源码 编辑:程序博客网 时间:2024/06/16 02:42
B. Code Parsing
Time Limit : 4000/2000ms (Java/Other) Memory Limit : 524288/262144K (Java/Other)
Total Submission(s) : 1 Accepted Submission(s) : 1
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:
- 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 strings.
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 most106 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 strings.
xyxyxy
xy
这道题 说 字符串仅由xy组成,有两个规则 如果有yx的话 可以转化为xy 如果是xy 就可以消去
也就是说只要我们无数次的运用第一条规则 就可以把x都放在前面,y都放在后面 然后再消去 xy 这样 本题就转化为 统计x与y数量多少的题目了。。。。orz
#include<iostream>#include<string>using namespace std;int main(){string str;int num;while(cin>>str){num=0;for(int i=0;i<str.length();i++){if(str[i]=='x') num++;else num--;}if(num>0) {for(int i=0;i<num;i++) cout<<"x";}else{num=-num;for(int i=0;i<num;i++) cout<<"y";cout<<endl;}}}
- hdu B. Code Parsing
- B. Code Parsing
- B. Code Parsing
- Code Parsing CodeForces
- hdu 4018 Parsing URL
- HDU--4018(Parsing URL)
- hdu 4018 Parsing URL
- HDU 4018 Parsing URL
- hdu 4018 Parsing URL
- HDU 4018 Parsing URL
- hdu 4018 Parsing URL
- HDU 4081-Parsing URL(水)
- Clang AST parsing for automated code generation
- Code HDU
- cf:B-QR code
- B-Cracking the Code
- Code forces 699B
- code force 363B
- Linux系统的启动过程
- 深入理解PCA
- uva-748
- IPC组件的分装之条件变量(14)
- poj2488
- hdu B. Code Parsing
- android alertdialog 点击其他区域消失
- UVa 10177 (2/3/4)-D Sqr/Rects/Cubes/Boxes?
- Linux ALSA声卡驱动之一:ALSA架构简介[zz]
- SimpleDateFormat的parse方法转换抛出NumberFormatException异常
- [Usaco2007 Open]Cheappal-DP合并类
- init.rc中command案例使用
- php获取当前类名函数名的方法
- uva 11997 - K Smallest Sums