/******************************************************************************************************
** Copyright (C) 2011.07.01-2013.07.01
** Author: famousDT <13730828587@163.com>
** Edit date: 2011-10-06
******************************************************************************************************/
#include <stdio.h>
#include <stdlib.h>//abs,atof(string to float),atoi,atol,atoll
#include <math.h>//atan,acos,asin,atan2(a,b)(a/b atan),ceil,floor,cos,exp(x)(e^x),fabs,log(for E),log10
#include <vector>
#include <queue>
#include <map>
#include <time.h>
#include <set>
#include <stack>
#include <string>
#include <iostream>
#include <assert.h>
#include <string.h>//memcpy(to,from,count
#include <ctype.h>//character process:isalpha,isdigit,islower,tolower,isblank,iscntrl,isprll
#include <algorithm>
using namespace std;
//typedef long long ll;
#define MY_PI acos(-1)
#define MY_MAX(a, b) ((a) > (b) ? (a) : (b))
#define MY_MIN(a, b) ((a) < (b) ? (a) : (b))
#define MY_MALLOC(n, type) ((type *)malloc((n) * sizeof(type)))
#define MY_ABS(a) (((a) >= 0) ? (a) : (-(a)))
#define MY_INT_MAX 0x7fffffff
/*==========================================================*\
|
\*==========================================================*/
char s[1000000 + 5];
struct node
{
int front, next;
char c;
} L[1000000 + 100000];
int main()
{
int cases;
cin>>cases;
getchar();
while (cases--) {
gets(s);
int i;
int l = strlen(s);
int pos = 0;
int f, n;
int index = 0;
L[0].front = L[0].next = -1;
L[0].c = '\0';
for (i = 0; i < l; ++i) {
if (s[i] == '-') {
if (pos > 0) {
f = L[pos].front;
n = L[pos].next;
L[f].next = n;
L[n].front = f;
pos = f;
}
} else if (isalpha(s[i]) || isdigit(s[i])) {
++index;
n = L[pos].next;
L[pos].next = index;
L[index].c = s[i];
L[index].front = pos;
L[index].next = n;
L[n].front = index;
pos = index;
} else if (s[i] == '<' && L[pos].front != -1) {
pos = L[pos].front;
} else if (s[i] == '>' && L[pos].next != -1) {
pos = L[pos].next;
}
}
pos = 0;
while (L[pos].next != -1) {
printf("%c", L[L[pos].next].c);
pos = L[pos].next;
}
printf("\n");
}
return 0;
}
SOJ-4072(数组模拟双向链表)
最新推荐文章于 2024-07-25 16:42:46 发布