【链表】【UVA11988】Broken Keyboard】的更多相关文章

题目大意:将一个字符串改变顺序后输出.遇到“[”就将后面内容拿到最前面输出,遇到“]”就将后面的内容拿到最后面输出. 题目分析:用nxt[i]数组表示i后面的字符的下标,实际上就是以字符i为头建立链表,写法类似链式前向星. 代码如下: # include<iostream> # include<cstdio> # include<cstring> # include<algorithm> using namespace std; char p[100005]…
向量和数组的优势是可以随机的存取元素和在末尾添加删除元素,而当插入元素时,需要移动大量的数据,消耗大量的时间.而链表的优势是可以在O(1)删除和插入数据.所以在频繁移动元素时,可以使用链表. 分析:如果用一个数组来保存,题目中的文本随着光标位置的移动需不断的插入字符,这样会导致大量字符移动问题.解决方案是采用链表,将字符串保存在buf[1...n]中,然后用next[i]表示下标为i的字符的下一个位置的下标(链表不一定用指针实现).为了方便起见,用一个虚拟的next[0]指向显示屏最右边的字符下…
参考:https://blog.csdn.net/lianai911/article/details/41831645 #include <iostream> #include <cstdio> #include <cstring> #include <vector> using namespace std; ;//若在函数内开过大数组,会显示Process returned -1073741571 (0xC00000FD)错误! string s; vec…
题目链接:https://vjudge.net/problem/UVA-11988 题目大意: 键盘的home键和end键出现了问题. 在输入一段文本时,home键或end键可能会自动被按下,home键会使光标移动到文章开头,end键会使光标移动到文章结尾. 输入包含多组数据,每组数据一行,包含不超过100000个字母,表示输入文本.[表示home键按下,]表示end键按下. 对每组输入输出一行,表示你在显示屏上看到的文本. Sample Input This_is_a_[Beiju]_text…
链表的思想很简单,要做到活用也不难.一般我是这样做得,从实际问题出发,先高度的概括符不符合链表的特点.能不能用链表简单解决.接着,就是编码.链表编码要理清细节性思路,最好是简单的画下图,正如改题的链表,本质上是循环链表.last指向最后一个节点.其next指针一定指向头节点.我们把s[0]当做头节点.                            last = cur = 0;         next[0] = 0;                                   …
题目复制太麻烦了,甩个链接 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18693 直接模拟光标操作时间复杂度较高,所以用链表存储顺序. pos表示光标位置 #include<cstdio> #include<iostream> #include<cstring> #include<algorithm> #include<cmath> using namespace st…
题目链接: 传送门 Broken Keyboard #include<bits/stdc++.h> using namespace std; char str[100010]; int main() { while(scanf("%s",str)!=EOF) { deque<int > q; int i=0; while(str[i]=='['||str[i]==']') i++; q.push_front(i); while(str[i]) { if(str[…
/*数组形式描述链表:链表不一定要用指针. 题目链接:UVa 11988 Broken Keyboard 题目大意: 小明没有开屏幕输入一个字符串,电脑键盘出现了问题会不定时的录入 home end 两个键, 我们知道如果录入home则将光标定位到字符首,如果录入end则是将光标定位到字符尾.现 在让你输出这段坏了文本. 表示:home => '[' , end => ']' 举例: input: hello[_Tom_]! output: _Tom_hello! 解题思路: 数组中频繁移动元…
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 problemwith the keyboard is that sometimes the “home” key or the “end” key gets automatically pressed(internally).Yo…
You're typing a long text with a broken keyboard. Well it's not so badly broken. The only problem with the keyboard is that sometimes the "home" key or the "end" key gets automatically pressed (internally). You're not aware of this iss…