Examples 6-4 broken chessboard uva 11988

This sample item relates to the usage of some way linked list,
first, a one-way linked list at the time of recording, just consider who followed him, then how to do it the first number,
through a dummy initial next [0] to save first bit, and when the last one that is nex [pos] = 0 when the
second, alphanumeric need to learn as a problem, that is, when writing the list, with numbers instead of letters

code show as below

#include <bits/stdc++.h>
using namespace std;
const int MA  = 1e5 + 5;
char s[MA];
int nex[MA];
int main()
{
	while (scanf("%s",s+1) == 1)
	{
		memset(nex,0,sizeof(nex));
		int n = strlen(s+1),pos = 0,wend = 0,k = 0;
		//pos表示位置,wend表示末位对应的数字 
		for (int i = 1; i <= n; i++)
		{
			if(s[i] == '[') pos = 0;
			else if(s[i] == ']') pos = wend;
			else{
				nex[i] = nex[pos];
				nex[pos] = i;//它的下一位
				pos = i;
				if (nex[pos] == 0) wend = pos;	
			}
		}
		while(nex[k])
		{
			printf("%c",s[nex[k]]);	
			k = nex[k] ;
		}
		printf("\n"); 
	}	
} 
Published 55 original articles · won praise 1 · views 2640

Guess you like

Origin blog.csdn.net/qq_37548017/article/details/102805533