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

本文介绍了一种使用链表实现文本处理的技术,包括输入文本的解析、节点操作及输出文本的方法。

 

题目传送门

题意:训练指南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;
}

  

转载于:https://www.cnblogs.com/Running-Time/p/5129878.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值