Uva - 11988 - Broken Keyboard (a.k.a. Beiju Text)
2015-06-14 18:58
531 查看
用链表,不必用结构体方式,太麻烦,直接用数组把字符串存起来,比如字符数组为s,用next[i]表示当前字符下一个应该显示字符的位置,就OK了。
直接用数组做,然后插入的时候移动数组是很不好的,很有可能超时,每次移动耗费时间太多。
AC代码:
#include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <algorithm> #include <stack> #include <queue> #include <bitset> #include <cassert> using namespace std; const int maxn = 100005; int last, cur, nextP[maxn]; // 光标在cur号字符后面 char s[maxn]; int main() { while (scanf("%s", s + 1) == 1) { int n = strlen(s + 1); last = cur = 0; nextP[0] = 0; for (int i = 1; i <= n; i++) { char ch = s[i]; if (ch == '[') { cur = 0; } else if (ch == ']') { cur = last; } else { nextP[i] = nextP[cur]; nextP[cur] = i; if (cur == last) { // 更新最后一个字符编号 last = i; } cur = i; // 移动光标 } } for (int i = nextP[0]; i != 0; i = nextP[i]) { printf("%c", s[i]); } cout << endl; } return 0; }
相关文章推荐
- 敏捷开发的一些理解
- 面向对象程序设计
- 第3方模块编译及一致性哈希应用
- 内网渗透之-域渗透基础
- linux安全配置记录
- Java异常处理的注意点总结
- linux命令记录
- centos 5.5 部署apache configure: error: APR not found. Please read the docume
- 简单的android闹钟
- Android 学习控件1-TextView
- CentOS防火墙配置
- 生产者-消费者问题
- laytpl.js 模板使用记录
- 结对项目开发电梯调度 - 整体设计
- hibernate jdbc jpa 事务超时
- 【WEB小工具】EncodingFilter—设置全局编码
- 图形学复习2——几何变换
- 再转JavaScript中的this
- win10预览版怎么升级win10正式版 自动升级win10教程
- php web编程使用的工具总结