SOJ-4072(数组模拟双向链表)

/****************************************************************************************************** 
 ** 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;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值