80分超时
查看原帖
80分超时
897952
ComputerStudents楼主2024/3/9 14:28

#include<bits/stdc++.h>
using namespace std;
struct node{
	int data;
	node *next;
};
node *head;
int n,tp,x,y;
int main(){
	node *p=new node;
	p->data=1;
	p->next=NULL;
	head=p;
	cin >> n;
	while(n--){
		cin >> tp;
		if(tp==1){
			cin >> x >> y;
			node *q=new node;
			q->data=y;
			q->next=NULL;
			p=head;
			while(p!=NULL){
				if(p->data==x){
					q->next=p->next;
					p->next=q;
					break;
				}
				p=p->next;
			}
		}else if(tp==2){
			cin >> x;
			p=head;
			bool f=1;
			while(p->next!=NULL){
				if(p->data==x){
					cout << p->next->data << endl;
					f=0;
					break;
				}
				p=p->next;
			}
			if(f==1){
				cout << 0 << endl;
			}
		}else{
			cin >> x;
			p=head;
			while(p!=NULL){
				if(p->data==x){
					p->next=p->next->next;
					break;
				}
				p=p->next;
			}
		}
	}
	return 0;
}

2024/3/9 14:28
加载中...