SGU 397 链表 或者 两个栈。
来源:互联网 发布:windows最新服务器系统 编辑:程序博客网 时间:2024/05/18 02:52
一开始觉得这个题要平衡树来做。。。
毕竟要动态的插入。。
毕竟啊,平衡树的插入是 logn 的是因为他一开始不知道把元素插入到哪里。
通过寻找,然后才插入的,这个我一开始就知道他应该插入哪里,所以,根本用不着平衡树,链表就OK了。
虽然很简单。。但是是第一次用 STL 的链表
栈
#include <stdio.h>#include <iostream>#include <queue>#include <algorithm>#include <map>#include <vector>#include <cmath>#include <string.h>#include <stdlib.h>#include <time.h>#include <fstream>#include <set>#include <stack>#include <list>using namespace std;#define READ freopen("acm.in","r",stdin)#define WRITE freopen("acm.out","w",stdout)#define ll long long#define ull unsigned long long #define uint unsigned int#define PII pair<int,int>#define PDD pair<double,double>#define fst first#define sec second#define MS(x,d) memset(x,d,sizeof(x))#define INF 0x3f3f3f3f#define ALL(x) x.begin(),x.end()#define PB push_back#define MOD 99991#define MAX 1111111
链表
list<char> l;list<char>::iterator it;stack<char> f,b;string s;int main(){ READ; while(cin>>s) { while(!f.empty()) f.pop(); while(!b.empty()) b.pop(); for(int i=0;i<s.size();i++) { if(s[i]=='L') if(!f.empty()) { b.push(f.top()); f.pop(); } if(s[i]=='R') if(!b.empty()) { f.push(b.top()); b.pop(); } if(s[i]>='a'&&s[i]<='z') f.push(s[i]); } while(!f.empty()) { b.push(f.top()); f.pop(); } while(!b.empty()) { printf("%c",b.top()); b.pop(); } cout<<endl; } return 0;}
#include <stdio.h>#include <iostream>#include <queue>#include <algorithm>#include <map>#include <vector>#include <cmath>#include <string.h>#include <stdlib.h>#include <time.h>#include <fstream>#include <set>#include <stack>#include <list>using namespace std;#define READ freopen("acm.in","r",stdin)#define WRITE freopen("acm.out","w",stdout)#define ll long long#define ull unsigned long long #define uint unsigned int#define PII pair<int,int>#define PDD pair<double,double>#define fst first#define sec second#define MS(x,d) memset(x,d,sizeof(x))#define INF 0x3f3f3f3f#define ALL(x) x.begin(),x.end()#define PB push_back#define MOD 99991#define MAX 1111111list<char> l;list<char>::iterator it;stack<char> f,b;string s;int main(){ READ; while(cin>>s) { l.clear(); //cout<<s<<endl; it=l.begin(); for(int i=0;i<s.length();i++) { //cout<<i<<" "; if(s[i]=='L') if(it!=l.begin()) it--; if(s[i]=='R') if(it!=l.end()) it++; if(s[i]>='a'&&s[i]<='z') l.insert(it,s[i]); } for(it=l.begin();it!=l.end();it++) cout<<(*it); cout<<endl; } return 0;}
0 0
- SGU 397 链表 或者 两个栈。
- sgu 397
- SGU 397
- sgu 397 TextEditor
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- (SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- SGU
- ACE_TMAIN的解析
- javascript原生选择器的一些基本方法
- Mysql Case 使用
- 实现ListView的分页加载功能
- Flask-babel简单实例
- SGU 397 链表 或者 两个栈。
- Unity3D 使用 RenderTexture 做 UI 特效、动态阴影
- linux标准目录结构
- 80端口被NT kernel & System 占用pid 4
- Android Service 服务 安卓广播机制
- Windows Tree命令
- 算法学习建议
- OpenGIS简单介绍
- 工作流 消息中心打开单据提示找不到第三方类