题目链接:

http://codeforces.com/contest/670/problem/E

题解:

用STL的list和stack模拟的,没想到跑的还挺快。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<list>
#include<stack>
using namespace std; const int maxn = + ;
const int INF = 2e9;
typedef __int64 LL; int n, m, pos;
char str[maxn];
list<char> ml;
stack<char> ms; void init() {
ml.clear();
} int main() {
while (scanf("%d%d%d", &n, &m, &pos) == && n) {
pos--;
init();
scanf("%s", str);
for (int i = ; i < n; i++) {
ml.push_back(str[i]);
}
scanf("%s", str);
list<char>::iterator it = ml.begin();
while (pos--) ++it;
for (int i = ; i < m; i++) {
if (str[i] == 'L') it--;
else if (str[i] == 'R') it++;
else {
ms.push(*it);
list<char>::iterator p = it;
if (*p == '(') {
while (!ms.empty()) {
++p;
if (ms.top() == '('&& *p == ')') ms.pop();
else ms.push(*p);
}
++p;
it = ml.erase(it, p);
}
else {
while (!ms.empty()) {
--p;
if (*p == '('&&ms.top() == ')') ms.pop();
else ms.push(*p);
}
++it;
it = ml.erase(p, it);
}
if (it == ml.end()) --it;
}
}
for (it = ml.begin(); it != ml.end(); it++) printf("%c", *it);
printf("\n");
}
return ;
}

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 给你n长度的括号字符,m个操作,光标初始位置是p,'D'操作表示删除当前光标所在的字符对应的括号字符以 ...

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

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

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

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

  6. cf670E Correct Bracket Sequence Editor

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

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

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

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

  9. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

随机推荐

  1. Oracle一些常用的查询命令总结(持续更新)

    更新于:2015年1月28日 17:08:13 -------------------------表空间 --------------------------------------- ----- 查 ...

  2. Windows2003 Apache 关闭安全 开启错误输入到屏幕上

    早上帮客户迁移网站的时候发现,打开网站是空白,什么都没报错,环境也是自己配置的,在客户的网站主目录写个测试页也可以打开,环境是APache+PHP5.2的新环境,当时就有点郁闷了,去Apache的er ...

  3. 理解 JavaScript Scoping & Hoisting(二)

    理解 JavaScript Scoping & Hoisting(二) 转自:http://www.jb51.net/article/75090.htm 这篇文章主要介绍了理解 JavaScr ...

  4. RF-BM-S02(V1.0)蓝牙4.0模块 使用手册

    一.产品概述 图1 RF-BM-S02纯硬件模块 RF-BM-S02是一款采用美国德州仪器TI 蓝牙4.0 CC2540作为核心处理器的高性能.超低功耗(Bluetooth Low Energy)射频 ...

  5. char型变量理解

    char  c = 128; printf("%d", c); 问输出是多少? 正确答案应该是-128. 如下几种情况: char c=128;printf("%u\n& ...

  6. .NET设计模式系列文章 from TerryLee

    http://www.cnblogs.com/Terrylee/archive/2006/07/17/334911.html 最初写探索设计模式系列的时候,我只是想把它作为自己学习设计模式的读书笔记来 ...

  7. Android触摸屏配置调试

    前几天搞乐蛙时,进入后是鼠标模式,好坑爹的模式有木有~~ 但是大蛋给出了解决方法,我不怕不怕啦~让我们向大牛致敬!!! 首先输入Command查看你的input配置~ adb shell dumpsy ...

  8. Why string is immutable in Java ?

    This is an old yet still popular question. There are multiple reasons that String is designed to be ...

  9. hdu 2091 空心三角形

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2091 空心三角形 Description 把一个字符三角形掏空,就能节省材料成本,减轻重量,但关键是为 ...

  10. core java 7 exception

    MODULE 7 Exceptions---------------------------- 程序正常执行过程中遇到的意外情况 引发异常的因素: 1)程序本身的内在因素 2)外部因素引发的,程序无须 ...