UVa 11988 array analog linked list

Source: Internet
Author: User

Title: On a computer without a monitor input a string, the keyboard is broken, will randomly appear home, and end button,

The string ' [' stands for the Home key (the first sentence), '] ' represents the end key (the end of the sentence) and asks the format of the last output string.

Analysis: Simulate screen operation, move cursor, simulate buffer output operation.

Description: The array simulates the list operation, follows the list operation, and visualizes the simulation.

1 //UVa11988 Broken Keyboard2 //Rujia Liu3#include <cstdio>4#include <cstring>5 Const intMAXN =100000+5;6 intLast, cur, next[maxn];//cursor is behind cur appended7 CharS[MAXN];8 9 intMain () {Ten    while(SCANF ("%s", s+1) ==1) { One     intn = strlen (s+1);//input saved in s[1], s[2] ... In Alast = cur =0; -next[0] =0; -  the      for(inti =1; I <= N; i++) { -       CharCH =S[i]; -       if(ch = ='[') cur =0; -       Else if(ch = =']') cur =Last ; +       Else { -Next[i] =Next[cur]; +Next[cur] =i; A         if(cur = = last) last = i;//Update "Last character" number atcur = i;//Move Cursor -       } -     } -      for(inti = next[0]; I! =0; i =Next[i]) -printf"%c", S[i]); -printf"\ n"); in   } -   return 0; to}

UVa 11988 array analog linked list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.