uva 11988 - Broken Keyboard (a.k.a. Beiju Text)----链表快速插入
2015-09-05 23:27
309 查看
// // main.cpp // uva 11988 - Broken Keyboard (a.k.a. Beiju Text)----链表快速插入 // // Created by XD on 15/9/5. // Copyright (c) 2015年 XD. All rights reserved. // /* 此题就是一道简单的链表题。注意一下当前的位置,起始位置和结束位置。 */ #include <iostream> #include <string> #include <queue> #include <stack> #include <stdio.h> #include <stdlib.h> #include <math.h> #include<vector> #include <string.h> #include <string> #include <algorithm> #include <set> #include <map> #include <cstdio> using namespace std ; struct node{ int key ; node* pre; node* nxt ; }; node* getNode(int key) { node* ret = (node*)malloc(sizeof(node)) ; ret->key = key ; return ret ; } node *header,*stop,*current ; void insert(node* n1,node*n2,node* n3) { n1->nxt = n3 ; n3->nxt = n2 ; n2->pre = n3 ; n3->pre = n1 ; current = n3 ; } void init() { header = getNode(-1) ; stop = getNode(-1) ; header->pre = NULL ; header->nxt = stop ; stop->nxt = NULL ; stop->pre = header ; current = header ; } int main(int argc, const char * argv[]) { char s[100010] ; while (scanf("%s" , s) == 1) { init() ; int len = (int)strlen(s) ; for (int i = 0; i < len; i++) { if (s[i] == '[') { current = header ; } else if(s[i] == ']') { current=stop->pre ; } else{ insert(current, current->nxt,getNode(s[i])) ; } } header = header->nxt ; while (header->key!=-1) { printf("%c",header->key) ; header = header->nxt ; } printf("\n") ; } return 0; }
相关文章推荐
- phpExcel中文帮助手册
- Java实现文件的读写,复制
- CSS 让标点符号不出现在行首
- HDU 1024 Max Sum Plus Plus(二维数组转化为一维数组)
- [JavaWeb基础] 016.Struts2 国际化配置
- 【FLEX4.6从浅入深,】比4.5内容增加了很多新的属性
- [LinkerScript.7] 简单的链接器脚本命令: 区域别名 - Simple Linker Script Commands : Region Alias
- 快速掌握iOS开发 - 多线程开发技巧
- 查询oracle中所有用户信息
- 一 、前言
- angular attrs.$observe和$scope.$watch的区别
- Java第一周:1.17
- 指向函数的指针
- 第一次玩sketchup做个小模型
- hdu5167 Fibonacci set和map
- C++ 取得数组长度
- JS relearn note Ⅰ
- Struts2入门-Hello Word实例
- 为什么PreparedStatement execute执行插入成功却返回false
- 1033. To Fill or Not to Fill (25)