使用list来模拟就行了,如果熟悉list,那么这道题真是分分钟秒掉。。。

list是双向循环链表,插入和删除操作非常快,缺点是不能像数组一样随机按下标读取。

一下是wiki上说明的相关函数:http://zh.wikipedia.org/wiki/List_(STL)

  • Iterators:

    • list.begin() 回传指向第一个元素的 Iterator。
    • list.end() 回传指向最末元素的下一个位置的 Iterator。
    • list.rbegin() 回传指向最末个元素的反向 Iterator。
    • list.rend() 回传指向第一个元素的前一个位置的反向 Iterator。
  • Capacity/Size:

    • list.empty() 若list内部为空,则回传true值。
    • list.size() 回传list内实际的元素个数。
    • list.resize() 重新分派list的长度。
  • Element Access

    • list.front() 存取第一个元素。
    • list.back() 存取最末个元素。
  • Modify methods

    • list.push_front() 增加一个新的元素在 list 的前端。
    • list.pop_front() 删除 list 的第一个元素。
    • list.push_back() 增加一个新的元素在 list 的尾端。
    • list.pop_back() 删除 list 的最末个元素。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const double eps=1e-;
const int INF=; const int maxn=+;
char s[maxn];
list<char>l; int main()
{
//freopen("in1.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%s",s)==)
{
int len=strlen(s);
list<char>::iterator it=l.begin();
for(int i=;i<len;i++)
{
if(s[i]=='[')
{
it=l.begin();
}
else if(s[i]==']')
{
it=l.end();
}
else
{
l.insert(it,s[i]);
}
}
for(it=l.begin();it!=l.end();it++)
{
putchar(*it);
}
printf("\n");
l.clear();
}
return ;
}

最新文章

  1. proxifier 3.29 key
  2. 《Hey程序员 你适合加入创业公司吗?》再补充
  3. EXTJS 资料 Ext.Ajax.request 获取返回数据
  4. JavaScript入门(6)
  5. PHP学习笔记十二【数组排序】
  6. 为什么用Object.prototype.toString.call(obj)检测对象类型?
  7. 【前端调试手机页面】分享一款便捷的调试工具--spy-debugger
  8. spring boot summer快速开发框架之《一、数据库操作》
  9. phpcms模板生成原理
  10. jmeter生成html格式接口自动化测试报告
  11. https处理的一个过程,对称加密和非对称加密
  12. 五、activiti工作流-学生请假流程
  13. Open SuSE中自定义的环境变量
  14. C#实现微信AES-128-CBC加密数据的解密
  15. 【译】第22节---Fluent API - EntityTypeConfiguration类
  16. nodejs 遍历文件夹下所有的图片改名为中文
  17. 在win和android上同时进行OpenCV程序设计
  18. 转:MVC框架
  19. 进程上下文VS中断上下文
  20. linux普通用户免秘钥登录(xshell工具环境)

热门文章

  1. 4.5 基于STM32+MC20远程短信控制开关
  2. Google Cloud Platfrom中使用Linux VM
  3. HTML中表格的使用
  4. input propertyChange
  5. 转:Windows下USB接口驱动技术(二)
  6. Ajax在jQuery中的应用---加载异步数据
  7. 每天一个Linux命令(46)ifconfig命令
  8. unicode和utf8
  9. jQuery带缩略图焦点图插件
  10. Swift_初识Swift