题目链接: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 (链表)的更多相关文章

  1. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 栈 链表

    E. Correct Bracket Sequence Editor 题目连接: http://www.codeforces.com/contest/670/problem/E Description ...

  2. 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 ...

  3. Codeforces Round #350 (Div. 2) E. Correct Bracket Sequence Editor 模拟

    题目链接: http://codeforces.com/contest/670/problem/E 题解: 用STL的list和stack模拟的,没想到跑的还挺快. 代码: #include<i ...

  4. Codeforces 670E - Correct Bracket Sequence Editor - [链表]

    题目链接:https://codeforces.com/contest/670/problem/E 题意: 给出一个已经匹配的括号串,给出起始的光标位置(光标总是指向某个括号). 有如下操作: 1.往 ...

  5. CodeForces 670E Correct Bracket Sequence Editor(list和迭代器函数模拟)

    E. Correct Bracket Sequence Editor time limit per test 2 seconds memory limit per test 256 megabytes ...

  6. 【31.93%】【codeforces 670E】Correct Bracket Sequence Editor

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. cf670E Correct Bracket Sequence Editor

    Recently Polycarp started to develop a text editor that works only with correct bracket sequences (a ...

  8. 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 ...

  9. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

随机推荐

  1. 如何过滤 adb logcat 输出

    对原作者表示感谢,转自博客:http://www.otechu.me/zh/2011/12/filtering-adb-logcat-output/ 本文介绍如何在 shell 命令行中过滤 adb ...

  2. asp.net获取当前页面源码并生成静态页面

    StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(strin ...

  3. 原创:js代码, 让dedecms支持Tag选择, 添加内容更为方便,不用手输Tag

    dedecms在编辑修改内容时,TAG标签需要手动输,中文的Tag, 中间还得用半角字符','分隔,  输入法切来切去很不方便,   于是动手改后台代码, 利用后台的tags_main.php, 让d ...

  4. Android Configuration change引发的问题及解决方法(转)

    之前在学习Fragment和总结Android异步操作的时候会在很多blog中看到对Configuration Change的讨论,以前做的项目都是固定竖屏的,所以对横竖屏切换以及横竖屏切换对程序有什 ...

  5. Spring 事务管理原理探究

    此处先粘贴出Spring事务需要的配置内容: 1.Spring事务管理器的配置文件: 2.一个普通的JPA框架(此处是mybatis)的配置文件: <bean id="sqlSessi ...

  6. HDU 5765 Bonds 巧妙状压暴力

    题意:给一个20个点无向连通图,求每条边被多少个极小割集包括 分析:极小割集是边的集合,很显然可以知道,极小割集恰好吧原图分成两部分(这个如果不明白可以用反证法) 然后就是奉上官方题解:http:// ...

  7. [OFBiz]开发 五

    1.初学者例程:OFBiz Tutorial - A Beginners Development Guidehttps://cwiki.apache.org/confluence/display/OF ...

  8. CABasicAnimation 使用

    1. 基本使用 UIView * view = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 50,50)]; view.backgroundColo ...

  9. motan解读:添加spring 支持

    代码位置: motan-core的目录下       motan中使用spring管理配置对象.motan利用Spring的spi机制创建了自定义标签和相应的标签处理代码.具体使用方法见这篇.本文以m ...

  10. Nonlinear Transform

    前文中,我们已经学习了linear classification,linear regression,logistic regression三种线性方法. 如何解决这种问题呢? 其实很好解决,只需要加 ...