80分TLE
查看原帖
80分TLE
1468509
zhangchenyue01楼主2024/10/11 22:17
#include <bits/stdc++.h>
using namespace std;
struct node
{
	int data;
	node* next;
};
node *root;
node *n;
int q;
void add(node *now,int f,int ins)
{
	if(now->data==f)
	{
		n=new node;
		n->data=ins;
		n->next=now->next;
		now->next=n;
	}
	else
	{
		add(now->next,f,ins);
	}
	return;
}
void visi(node *now,int f)
{
	if(now->data==f)
		cout<<now->next->data<<endl;
	else
		visi(now->next,f);
	return;
}
void dele(node *now,int f)
{
	if(now->data==f)
		now->next=now->next->next;
	else
		dele(now->next,f);
	return;
}
int main()
{
	root=new node;
	root->data=1;
	root->next=new node;
	root->next->data=0;
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		int x,y,z;
		cin>>x;
		if(x==1)
		{
			cin>>y>>z;
			add(root,y,z);
		}
		if(x==2)
		{
			cin>>y;
			visi(root,y);
		}
		if(x==3)
		{
			cin>>z;
			dele(root,z);
		}
	}
	return 0;
}
2024/10/11 22:17
加载中...