题目链接:

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. POJ C程序设计进阶 编程题#1:分配病房

    编程题#1:分配病房 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 某个科 ...

  2. 一个用WPF做的简单计算器源代码

    一.界面设计XAML代码 <Window x:Class="fengjisuanqi.MainWindow" xmlns="http://schemas.micro ...

  3. 在SQL中取出字符串中数字部分或在SQL中取出字符部分

    在SQL中取出字符串中数字部分或在SQL中取出字符部分 编写人:CC阿爸 2013-10-18 近来在开发一个项目时,一包含数字的字符串,需要取出中间的数字部分进行排序.经过baidu搜索.并结合自己 ...

  4. HTML5 对于手机页面长按会粘贴复制的禁用 (解决方案)

    解决方案: 直接在CSS 文件中添加下面的代码,就可以实现了在手机端禁止粘贴复制的功能: *{    -webkit-touch-callout:none;  /*系统默认菜单被禁用*/    -we ...

  5. ElasticSearch部署

    安装jdk1.7 1.卸载Liunx自带的openjdk rpm -qa | grep jdk 查看当前的jdk版本 sudo yum -y remove java-1.7.0-openjdk-hea ...

  6. ansible的playbook组件

    playbook的核心元素: tasks: 任务 variables: 变量 templates: 模板 handlers: 处理器 roles: 角色 组织格式:YAML(被称为另外一种标记语言) ...

  7. Centos6.5环境下安装SVN 整合Apache+SSL

    弄了两天,终于在服务器上初步搭建起来了SVN(版本1.8). 服务器系统:Centos6.5 64位,搭建过程中全部采用源码编译安装(configure/make/make install),推荐大家 ...

  8. PHP MYSQLI中事务处理

    MYSQL事务处理让所有sql语句执行成功后才去处理,如果有一条没有成功或者报错就会回滚事务,防止敏感操作处理失败.MYSQL中只有INNODB和BDB类型的数据表才能支持事务处理!其它类型是不支持的 ...

  9. jQuery cookie插件保存用户登陆信息

    通过jquery cookie插件保存用户登录信息. 代码: <html>  <head>  <title>cookies.html</title>  ...

  10. 安装pdo.so和pdo_mysql.so还有pcntl.so扩展到php中

    1.下载源码,解压tar -xzvf php-5.4.20.tar.gz cd  /usr/local/src/php-5.4.20/ext/pdo /usr/local/php/bin/phpize ...