UVa11988
Broken Keyboard (a.k.a. Beiju Text)
有一个破损的键盘,当使用该键盘进行输入时会随机的按下home键和end,这就导致最终输出的文本会出现混乱。给定一个包含了home和end的字符串,确定最终屏幕上输出的字符串。
明确说了就是为了练习使用链表,所以也没什么可以选择的。
#include <iostream>
#include <list>
#include <string>
using namespace std;
int main()
{
string line;
while (cin >> line) {
list<char> text;
list<char>::iterator InsertIter = text.end();
for (char ch : line)
{
if (ch == '[') {
InsertIter = text.begin();
}
else if (ch == ']') {
InsertIter = text.end();
}
else {
text.insert(InsertIter, ch);
}
}
for (char ch : text)
{
cout << ch;
}
cout << endl;
}
return 0;
}
/*
This_is_a_[Beiju]_text
[[]][][]Happy_Birthday_to_Tsinghua_University
*/
本文解析了如何利用链表实现解决UVa 11988 BrokenKeyboard问题,通过理解键盘输入规则,掌握链表插入技巧来还原正确文本输出。

256

被折叠的 条评论
为什么被折叠?



