Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)
题目链接:http://codeforces.com/contest/670/problem/E
给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以内的所有字符(比如'(()())'),'R'操作表示右移光标,'L'操作表示左移光标。删除操作后光标向右移,要是再向右移没有字符的话,那就停在最后的字符上了。问你最后的括号字符是怎么样的。
这题用链表写简单多了,直接模拟操作就行了,我用stl里的list。
#include <bits/stdc++.h>
using namespace std;
char str[] , op[];
int main()
{
ios::sync_with_stdio(false);
int n , m , p , r = , l = ;
list <char> L;
cin >> n >> m >> p >> str >> op;
for(int i = ; i < n ; ++i)
L.push_back(str[i]);
auto index = L.begin();
while(--p) {
index++;
}
for(int i = ; i < m ; i++) {
if(op[i] == 'L') {
if(index != L.begin()) {
index--;
}
}
else if(op[i] == 'R') {
if(++index == L.end()) {
index--;
}
}
else {
l = r = ;
if(*index == ')')
r++;
else
l++;
if(l < r) {
L.erase(index--);
while(r != l) {
if(*index == ')')
r++;
else
l++;
L.erase(index--);
}
if(++index == L.end()) {
index--;
}
}
else {
L.erase(index++);
while(r != l) {
if(*index == ')')
r++;
else
l++;
L.erase(index++);
}
if(index == L.end()) {
index--;
}
}
}
}
index = L.begin();
for( ; index != L.end() ; ++index) {
cout << *index;
}
cout << endl;
}
Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor (链表)的更多相关文章
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表
E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 线段树模拟
E. Correct Bracket Sequence Editor Recently Polycarp started to develop a text editor that works o ...
- Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟
题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...
- Codeforces 670E - Correct Bracket Sequence Editor - [链表]
题目链接:https://codeforces.com/contest/670/problem/E 题意: 给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号). 有如下操作: 1.往 ...
- CodeForces 670E Correct Bracket Sequence Editor(list和迭代器函数模拟)
E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes ...
- 【31.93%】【codeforces 670E】Correct Bracket Sequence Editor
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- cf670E Correct Bracket Sequence Editor
Recently Polycarp started to develop a text editor that works only with correct bracket sequences (a ...
- Codeforces Round #350 (Div. 2) F. Restore a Number 模拟构造题
F. Restore a Number Vasya decided to pass a very large integer n to Kate. First, he wrote that num ...
- Codeforces Round #350 (Div. 2) D2. Magic Powder - 2
题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...
随机推荐
- URAL 1992
CVS Description Yoda: Visit I will the cloners on Kamino... And see this army they have created for ...
- Firefox和Chrome浏览器导出书签
Chrome浏览器: 或者直接在地址栏中输入:“chrome://bookmarks/#1”也可以 Firefox浏览器:
- UVa 11105 (筛法) Semi-prime H-numbers
题意: 你现在来到了一个所有的数都模4余1的世界,也就是除了这种数没有其他的数了. 然而素数的定义依然没变,如果一个数不能写成两个非1数字的乘积,则它是素数. 比如,在这里5就变成了最小的素数. 两个 ...
- Struts框架搭建时所遇到的问题
问题一:Unable to load configuration. - bean - jar:file:/D:/Tomcat%206.0/webapps/bar/WEB-INF 原 因:可 ...
- erl0002-erlang ets学习笔记
ets全称“erlang term storage” erlang项式存储. ets打破了erlang“不变数据”的原则,使得进程之间可以共享数据.首先引起的思考是为什么会出现ets?下面是对网络资料 ...
- 强制将IE8设置为IE7兼容模式来解析网页
强制将IE8设置为IE7兼容模式来解析网页 英文原文:http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx 文件兼容性用于定义让IE ...
- Js原型模式
function Person(){ } Person.prototype.name = "xd"; Person.prototype.age = 26; Person.proto ...
- CABasicAnimation(CAKeyframeAnimation)keypath 取值
- keyPath可以使用的key - #define angle2Radian(angle) ((angle)/180.0*M_PI) - transform.rotation.x 围绕x轴翻转 参 ...
- NSarray 赋值 拷贝 等问题记录
1. NSArray * a1 = @[@"1",@"2",@"3"]; NSArray * a2 = a1; a1跟a2所指向的地址是一样 ...
- Oracle归档方式设置
一 设置为归档方式Sql代码 sql> archive log list; #查看是不是归档方式 sql> alter system set log_archive_start=true ...