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