UVa 11998 broken Keyboard (array implementation linked list)

Source: Internet
Author: User

Test instructions

Enter a line of characters that contains ' [' and '] ', which means the home and end keys on the keyboard, and then the analog characters are entered on the keyboard. Enter the final result of a line

Analysis:

Using an array to simulate a linked list, in the list of the ends of the insertion of letters and then output, the method needs more practice to practice, in fact, a bit like the adjacency table.

For convenience, a virtual node is often placed before the first element of the list.

#include <bits/stdc++.h>using namespacestd;Const intMAXL =100000+7;intMain () {CharSTR[MAXL]; intcur, last; intNEXT[MAXL];//Next[index] is str[index] The next letter is Str[next[index]]//for convenience, a virtual node is often placed before the first element of the list. So start from Str+1 .     while(~SCANF ("%s", str+1))    {        intLen = strlen (str+1); next[0] =0;//start next point to the virtual nodecur = last =0;  for(inti =1; I <= Len; i++){            if(Str[i] = ='[') {cur=0; }        //cursor is behind cur cur...|            Else if(Str[i] = =']') {cur=Last ; }            Else{Next[i]=Next[cur]; Next[cur]=i; /*Note that these two sentences when cur = 0, i = 1 o'clock, next[1] = next[0]------------to connect the virtual node to next[1] next[0] = 1 ------------take the next 0 to 1, which means the next0 shifts to Next1 next0 to 1 .*/                if(cur = = last) last =i; Cur=i; }        }         for(inti = next[0]; I! =0; i =Next[i]) {printf ("%c", Str[i]); } puts (""); }}

UVa 11998 broken Keyboard (array implementation 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.