【悬赏1关注】20pts RE
查看原帖
【悬赏1关注】20pts RE
575655
Chtholly_is_cute楼主2023/7/10 22:52

RE on #3,4,5,6,7,8,9,10

code:

#include<bits/stdc++.h>
using namespace std;
struct node{
	int val;
	node *next;
	node(int vv):val(vv),next(NULL){
	}
};
node *head=new node(1);
void findinsert(int x,int y){
	node *p,*q;
	p=head;
	while(p){
		if(p->val==x)break;
		p=p->next;
	}
	if(p==NULL){
		cout<<"p==NULL"<<endl;
		return;
	}
	q=new node(y);
	q->next=p->next;
	p->next=q;
}
void finddelete(int x){
	node *p,*pre;
	p=head;
	while(p->val!=x){
		pre=p;
		p=p->next;
	}
	p=p->next;
	pre=pre->next;
	pre->next=p->next;
	free(p);
}
int query(int x){
	node *p=head;
	while(p->val!=x)p=p->next;
	if(p->next==NULL)return 0;
	return p->next->val;
}
int main(){
	int n;
	cin>>n;
	int op,x,y;
	for(int i=0;i<n;i++){
		cin>>op>>x;
		if(op==1){
			cin>>y;
			findinsert(x,y);
		}
		if(op==2)cout<<query(x)<<endl;
		if(op==3)finddelete(x);
	}
	return 0;
}
2023/7/10 22:52
加载中...