两种方法,直接上代码

STL标准模板库

#include <iostream>
#include <list>
#include <algorithm>
#include <cstdio>
using namespace std;
const maxn=100000+5;
char str[maxn];
typedef list<char> L;
int main(){
while(gets(str)){
L l;
L::iterator p;
int len=strlen(str);
for(int i=0;i<len;i++){
if (str[i]=='[') p=l.begin();
else if(str[i]==']') p=l.end();
else l.insert(p,str[i]);
}
for(p=l.begin();p!=l.end();p++)
printf("%c",*p);
printf("\n");
}
return 0;
}

数组模拟链表

#include <cstdio>
#include <cstring>
const int maxn=100000+5;
int last,cur,next[maxn];//光标位于cur字号的后面
char s[maxn];
int main(){
while(scanf("%s",s+1)==1){
int n=strlen(s+1);//输入保存在s[1],s[2],s[3],后面
cur=last=0;
next[0]=0;//头节点指向空
/*
从1到n逐个遍历
*/
for (int i=1;i<=n;i++){
char ch=s[i];
if (ch=='[') cur=0;
else if (ch==']') cur=last;
//交换性伴侣
else {
next[i]=next[cur];//新来的结点插向gay2p的后者
next[cur]=i;//gay2p的前者插向新来的结点
if (cur==last) last=i;//更新"最后一个字符"的编号
cur=i;//改变搜索2p对
}
}
for(int i=next[0];i!=0;i=next[i])
printf("%c",s[i]);
printf("\n");
}
return 0;
}

  

最新文章

  1. ASP.NET Core CORS 简单使用
  2. spring 定时任务@Scheduled
  3. javascript运算符语法概述
  4. Android和Linux应用综合对比分析
  5. .NET Core Preview
  6. DataTable得到某行某列的值
  7. mysql的事务和select...for update
  8. Hadoop on Mac with IntelliJ IDEA - 6 解决KeyValueTextInputFormat读取时只有key值问题
  9. poi实现将数据输出到Excel表格当中
  10. 邮箱格式验证demo
  11. 生产企业如何部署VMware虚拟化的解决方案
  12. Hadoop权威指南:HDFS-数据流
  13. SDS 链表
  14. Python 文档 涉及词汇
  15. html5的video标签自动播放
  16. 主席树入门——询问区间第k大pos2104,询问区间&lt;=k的元素个数hdu4417
  17. 关于数据库不适合docker的原因(摘抄)
  18. 1.Linux进程--进程标识号
  19. ubuntu下安装Firefox中国版解决Ubuntu与Windows下Firefox账号同步问题(已解决)
  20. Pycharm使⽤用秘笈v0.3PyCharm使⽤用秘籍

热门文章

  1. R语言重要数据集分析研究——&#160; 数据集本身的分析技巧
  2. 从Html5直播到互动直播,看直播协议的选择
  3. HTML行内元素、块状元素、行内块状元素的区别
  4. js中数学运算的处理
  5. Gist - ES6 Promise
  6. iOS多线程开发之离不开的GCD(上篇)
  7. RunTime 运行时
  8. 精通 JS正则表达式(转)
  9. 数据结构(C语言版)顺序表相关算法代码实现
  10. Newtonsoft.Json输出JSON 时动态忽略属性