zoukankan      html  css  js  c++  java
  • UVa 11988 数组模拟链表

    题目:在一个没有显示器的电脑上输入一个字符串,键盘坏掉了,会随机的出现home,和end按键,

            字符串中'['代表home键(句首),']'代表end键(句尾),问最后输出的字符串的格式。

    分析:模拟屏幕操作,移动光标,模拟缓冲区输出操作。

    说明:数组模拟链表操作。

    输入:This_is_a_[Beiju]_text

             [[]][][]Happy_Birthday_to_Tsinghua_University

    输出:BeijuThis_is_a__text
             Happy_Birthday_to_Tsinghua_University

     1 // UVa11988 Broken Keyboard
     2 // Rujia Liu
     3 #include<cstdio>
     4 #include<cstring>
     5 const int maxn = 100000 + 5;
     6 int last, cur, next[maxn]; // 光标位于cur号字符之后面
     7 char s[maxn];
     8 
     9 int main() {
    10   while(scanf("%s", s+1) == 1) {
    11     int n = strlen(s+1); // 输入保存在s[1], s[2]...中
    12     last = cur = 0;
    13     next[0] = 0;
    14 
    15     for(int i = 1; i <= n; i++) {
    16       char ch = s[i];
    17       if(ch == '[') cur = 0;
    18       else if(ch == ']') cur = last;
    19       else {
    20         next[i] = next[cur];
    21         next[cur] = i;
    22         if(cur == last) last = i; // 更新“最后一个字符”编号
    23         cur = i; // 移动光标
    24       }
    25     }
    26     for(int i = next[0]; i != 0; i = next[i])
    27       printf("%c", s[i]);
    28     printf("
    ");
    29   }
    30   return 0;
    31 }

    关于数组模拟链表 http://blog.csdn.net/jianxin1009/article/details/7952069

    理解问题:

  • 相关阅读:
    qt教程
    linux shell 教程
    CMakeList.txt学习
    tx2上直接编译带contrib cuda的opencv
    tx2 opencv交叉编译后的对应文件的放置位置
    opencv4.1.0 交叉编译遇到的问题
    docker 学习
    c++ 类注意点
    数据库整理(五)数据库编程 触发器 事务 过程
    数据库整理(四)数据库安全性与完整性
  • 原文地址:https://www.cnblogs.com/daijkstra/p/4446930.html
Copyright © 2011-2022 走看看