码迷,mamicode.com
首页 > 其他好文 > 详细

链表 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)

时间:2016-01-14 14:18:28      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

 

题目传送门

题意:训练之南P244

分析:链表模拟,维护链表的head和tail指针

#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 5;
struct Link_list    {
    char ch;
    Link_list *nex;
}link_list[N];

int main(void)  {
    while (true) {
         Link_list *head = link_list;
         Link_list *q = link_list + 1;
         head -> nex = NULL;
         Link_list *tail = head, *pos = head;
         char c;
         while (true)  {
            c = getchar ();
            if (c == ‘\n‘)  break;
            if (c == EOF)   return 0;
            if (c != ‘[‘ && c != ‘]‘) {
                Link_list *p = q++;
                p -> ch = c;
                p -> nex = pos -> nex;
                pos -> nex = p;
                pos = p;
                if (tail -> nex != NULL)    tail = pos;
            }
            else if (c == ‘[‘)  pos = head;
            else    pos = tail;
         }
         Link_list *p = head -> nex;
         while (p)   {
             printf ("%c", p -> ch);
             p = p -> nex;
         }
         puts ("");
    }

    return 0;
}

  

链表 UVA 11988 Broken Keyboard (a.k.a. Beiju Text)

标签:

原文地址:http://www.cnblogs.com/Running-Time/p/5129878.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!