UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)
使用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 ;
}
UVA 11988 Broken Keyboard (a.k.a. Beiju Text) (链表,模拟)的更多相关文章
- UVa 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
- UVA——11988 Broken Keyboard (a.k.a. Beiju Text)
11988 Broken Keyboard (a.k.a. Beiju Text)You’re typing a long text with a broken keyboard. Well it’s ...
- UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(链表)
题目代号:UVA 11988 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&pa ...
- 链表 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)
题目传送门 题意:训练指南P244 分析:链表模拟,维护链表的head和tail指针 #include <bits/stdc++.h> using namespace std; const ...
- UVa 11988 Broken Keyboard (a.k.a. Beiju Text)
题目复制太麻烦了,甩个链接 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18693 直接模拟光标操作时间复杂度较高,所以用链 ...
- 暑假集训单切赛第二场 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)(字符串处理)
一开始不懂啊,什么Home键,什么End键,还以为相当于括号,[]里的东西先打印出来呢.后来果断百度了一下. 悲催啊... 题意:给定一个字符串,内部含有'['和']'光标转移指令,'['代表光标移向 ...
- UVa 11988 - Broken Keyboard (a.k.a. Beiju Text) 题解
刘汝佳的题目,悲剧文本 -_-||| 这里使用vector<string>容器倒置记录数据,然后从后面输出就能够了. 难度就是不知道这种文档究竟哪里是開始输出,故此使用动态管理内存的容器比 ...
- B - Broken Keyboard (a.k.a. Beiju Text) 数组模拟链表
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem wi ...
- uva - Broken Keyboard (a.k.a. Beiju Text)(链表)
11988 - Broken Keyboard (a.k.a. Beiju Text) You’re typing a long text with a broken keyboard. Well i ...
随机推荐
- 爬虫二 requests模块的使用
一.requests模块的介绍 #介绍:使用requests可以模拟浏览器的请求,比起之前用到的urllib,requests模块的api更加便捷(本质就是封装了urllib3) #注意:reques ...
- 【整理学习Hadoop】Hadoop学习基础之二:分布式
分布式系统就是将系统的应用层,数据层或其它部分构架成分布(物理和逻辑上的都可以)状(通常是网状).分布式系统通常是为了增强系统的可扩展性.稳定性和执行效率.比如在线游戏通常就是分布系统,里面所谓的 ...
- 异动K线2--600532做一个分析时再给大家一只个股和近日大盘的分析
http://bbs.tianya.cn/post-stocks-612892-3.shtml ————看了一页就感觉没什么太大的意义 选时重于选股 这是一条股市生存的基本法则 看看天涯真正的高手 现 ...
- offsetLeft与style.left的区别
参考:http://www.cnblogs.com/woshilee/articles/1951457.html offsetLeft 获取的是相对于父对象的左边距 left 获取或设置相对于 具有定 ...
- iOS 点击注释图标 弹出对应解释
需求:如题目 接上一篇的开发内容 效果图: 这种情况存在tableView 的一个cell中. 要点 1, 弹出的对应解释 要在可视区域,并且小尖角 要指着 图片 2, 文本不能过高 有极大高度 ...
- 【leetcode刷题笔记】Palindrome Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the ...
- JSP笔记02——概述(转)
不完全翻译,结合谷歌,一定主观性,还可能有误,原始内容地址:https://www.tutorialspoint.com/jsp/jsp_overview.htm 主要内容如下: 什么是JSP? 为什 ...
- PHP的异常处理、错误的抛出及错误回调函数
一.错误.异常和等级常量表 error:不能再编译期发现运行期的错误,不如试图echo输出一个未赋值的变量,这类问题往往导致程序或逻辑无法继续下去而需要中断. exception:程序执行过程中出现意 ...
- 数据库系统概论学习4-SQL 语句和关系代数(二)单表查询
4.12 字符匹配 精确查询和模糊查询 在这一节之前,我们学习的查询几乎都是精确查询,这就需要我们明确地知道某些属性的具体值.例如我们需要查询 'Wangxiaoxiao' 同学的信息,就需要在WHE ...
- Go 书单
一.<Go语言学习笔记> (未找到对应版本的电子书,大家可以去作者github:https://github.com/qyuhen/book) 推荐理由:作为时下流行的一种系统编程语言,G ...