30求救!
查看原帖
30求救!
678447
CSPAK_Zhangxiuqi0011楼主2023/11/23 21:31

个人认为链表写得没有问题(刚学可能看不出来),但是30,WA 7个点,求调!

#include<bits/stdc++.h>
using namespace std;
struct node{
	int nxt;//nxt表示链表元素i表示的下一个元素是几 
}a[1000005]; 
void work(int what){
	if(what == 1){
		int x,y;
		cin>>x>>y;
		a[y].nxt = a[x].nxt;
		a[x].nxt = y;
		//  x    y        x.nxt
		//  x    x.nxt(y) y.nxt
	}else if(what == 2){
		int x;
		cin>>x;
		cout<<a[x].nxt<<"\n";
	}else{
		int x;
		cin>>x;
		a[x].nxt = a[a[x].nxt].nxt;
		a[a[x].nxt].nxt = 0;
		//  x     x.nxt    (x.nxt).nxt
		//  x              x.nxt
	}
}
int main() {
	int q;
	cin>>q;
	while(q--){
		int num;
		cin>>num;
		work(num);
	}
	return 0;
}

2023/11/23 21:31
加载中...