"Daily Learning", "non-pointer linked list" Uva11988-broken Keyboard (a.k.a. Beiju Text)

Source: Internet
Author: User

This topic dragged for several days, because I have two big natural enemies--linked list and tree tut see this topic know the original linked list can not use the pointer to write, but the same principle is the same, the equivalent is to use an array to simulate a list and not practical structure, the pointer in the structure of the body replaced by two variables cur and last. This topic was originally measured to be very strange and good because of the UVA AC HDU TLE Spoj re I was wondering, only to find that the different topics of the same name have three lanes tut

A detailed description of the topic has been written in the comments, the code:

#include <cstdio> #include <cstring>using namespace Std;const int maxn=100000+5;int LAST,CUR,NEXT[MAXN]; Char S[maxn];int main () {while (scanf ("%s", s+1) ==1) {int N=strlen (s+1);//input from s[1] Start storage last=cur=0;next[0]=0;// The next number of 0 positions is initialized to 0, which changes the for (int i=1;i<=n;i++) {//Output characters in order of the number of characters, which is a sequence of numbered sequences stored in next char ch=s[i];if (ch== ' [') cur=0 else if (ch== '] ') cur=last;else {next[i]=next[cur];//Now the next character position is the next "not inserted before current cursor next" A|c next[cur]=i;// The next of the current cursor is the position of the character that is now inserted, that is, if the cursor is still behind the previous character A|BC if (cur==last) last=i;//If it is currently the last, the last number updated to point to the last Next[last] is empty first compare then move cur cur=i;//moves the cursor to the current insertion character after ab|c}}for (int i=next[0];i!=0;i=next[i]) printf ("%c", s[i]);//Note the placeholder, in addition to the fact that the next array should be initialized to 0 printf (" \ n ");} return 0;}

--Emperor Taste clothe Xianyang, throughout, view the beginning of the emperor, lapels sighing Yue: "Sigh, man when so also!" ”

"Daily Learning", "non-pointer linked list" Uva11988-broken Keyboard (a.k.a. Beiju Text)

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.