80分代码悬关求调!TLE#9#10
查看原帖
80分代码悬关求调!TLE#9#10
920938
XingChen_MoNian楼主2024/7/14 14:28
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
struct node{
	int data;
	node* next;
};
int main(){
	node* p,*head;
	p=new node;
	p->data=1;
	p->next=NULL;
	head=p;
	int n;
	cin>>n;
	while(n--){
		int tp;
		cin>>tp;
		if(tp==1){
			int x,y;
			cin>>x>>y;
			node *q;
			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){
			int x;
			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{
			int x;
			cin>>x;
			p=head;
			while(p!=NULL){
				if(p->data==x){
					p->next=p->next->next;
					break;
				}
				p=p->next;
			}
		}
	}
	return 0;
}

悬赏关注

2024/7/14 14:28
加载中...