求大佬帮我看看为啥一直re
查看原帖
求大佬帮我看看为啥一直re
798360
logic_yzq楼主2022/11/17 18:05
#define  _CRT_SECURE_NO_WARNINGS 1
#include <bits/stdc++.h>
using namespace std;
//定义结构体
typedef struct _node
{
	char a;
	struct _node* next;
}node;
//创建链表的头
node* creatheadnode()
{
	node* headnode=(node*)malloc(sizeof(node));
	headnode->next = NULL;
	return headnode;
}
//创建链表的结点
node* creatnewnode(char str)
{
	node* newnode=(node*)malloc(sizeof(node));
	newnode->a = str;
	newnode->next = NULL;
	return newnode;
}
//在指定位置插入一个结点(插入p的后面)
void insertnode(node* p, node* newnode)
{
	newnode->next = p->next;
	p->next = newnode;
}

//打印链表
void shownode(node* headnode)
{
	node* point = headnode;
	while (point->next != NULL)
	{
		point = point->next;
		printf("%c", point->a);
	}
}
//释放链表内存
void freenode(node* headnode)
{
	node* point = headnode;
	while (point->next != NULL)
	{
		node* tmp = point->next;
		free(point);
		point = tmp;
	}
}

char arr[10086]; int len = 0;
int main()
{
	while (memset(arr,'\0',sizeof(arr)), scanf("%s", &arr) != EOF)
	{
		node* headnode = creatheadnode();
		len = strlen(arr);
		node* p = headnode;
		node* end_p = headnode;
		for (int i = 0; i < len; i++)
		{
			if (arr[i] == '[')
			{
				end_p = p;
				p = headnode;
			}
			else if (arr[i] == ']')
			{
				p = end_p;
			}
			else
			{
				node* newnode = creatnewnode(arr[i]);
				insertnode(p, newnode);
				p = p->next;
			}
		}
		shownode(headnode);
		printf("\n");
		freenode(headnode);
	}
	return 0;
}
2022/11/17 18:05
加载中...