sgu 397
来源:互联网 发布:淘宝店铺图片描述尺寸 编辑:程序博客网 时间:2024/06/01 07:26
手写链表
#include<cstdio>#include<cstring>using namespace std;char s;int tem,head,nex,last;struct word{ char c; int next; int last;}seq[1000100];int main(){ int i,f=1; //freopen("a.txt","r",stdin); //freopen("b.txt","w",stdout); while(scanf("%c",&s)!=EOF){ if(s=='\n'){ if(tem==0)continue; tem=head; while(tem!=-1){ printf("%c",seq[tem].c); tem=seq[tem].next; } printf("\n"); } if(s=='\n'||f){ tem=0;last=-1;head=0;nex=-1; f=0; memset(seq,0,sizeof(seq)); } if(s=='\n')continue; if(s!='L' && s!='R'){ seq[tem].c=s; seq[tem].last=last; seq[tem].next=nex; if(last!=-1) seq[last].next=tem; else if(last==-1) head=tem; if(nex!=-1) seq[nex].last=tem; tem++; seq[tem].last=tem-1; last=tem-1; } else if(s=='L'){ if(last==-1)continue; nex=last; last=seq[last].last; } else if(s=='R'){ if(nex==-1)continue; last=nex; nex=seq[nex].next; } }}
用stl的list
#include <cstdio>#include <cstring>#include <list>using namespace std;char org[1000001];int main(void) { list<char> word; scanf ("%s", org); int i; int len = strlen(org); list<char>::iterator it = word.begin(); for (i = 0; i < len; ++i) { if (org[i] == 'L') { if (it != word.begin()) { --it; } } else if (org[i] == 'R') { if (it != word.end()) { ++it; } } else { word.insert(it, org[i]); } } for (it = word.begin(); it != word.end(); ++it) { printf ("%c", *it); } printf ("\n"); return 0;}
- sgu 397
- SGU 397
- sgu 397 TextEditor
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU 397 链表 或者 两个栈。
- linux基础编程 链路层socket 摆脱winPcap 夸网段socket通信 可夸平台移植
- 堆排序及其分析
- 战斧湖战役之后的5rnm
- JavaDoc注释命令
- Android OpenGL ES 简明开发教程四:3D 坐标变换
- sgu 397
- Windows 7安装Eclipse 3.7搭建C/C++开发环境
- 腾讯游戏的5rnm
- 漫谈linux文件IO(转)
- Android OpenGL ES 简明开发教程三:3D绘图基本概念
- linux 内核的链表操作(好文不得不转)
- C的链表实现
- Hadoop在linux下安装和配置
- SecureCRT连接ubuntu