您的位置:首页 > 其它

UVA 11988 - Broken Keyboard (a.k.a. Beiju Text)

2014-07-26 12:43 507 查看


UVA 11988 - Broken Keyboard (a.k.a. Beiju Text)

题目链接

题意:给定一个文本,输入'['光标到开头,输入']'光标到结尾,问输入完之后对应的输出是什么

思路:用链表搞,遇到'['就把指针指到链表头,遇到']'就指到链表尾,其他就在指针位置插入即可

代码:

#include <cstdio>
#include <cstring>
#include <list>
#include <iostream>
using namespace std;

const int N = 100005;

char str
;
list<char> ans;

int main() {
while(gets(str)) {
int len = strlen(str);
ans.clear();
list<char>::iterator it = ans.begin();
for (int i = 0; i < len; i++) {
if (str[i] == '[') it = ans.begin();
else if (str[i] == ']') it = ans.end();
else ans.insert(it, str[i]);
}
for (it = ans.begin(); it != ans.end(); it++)
printf("%c", *it);
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: