RE求调
查看原帖
RE求调
1757786
Long_Dream楼主2025/7/2 16:56
#include<bits/stdc++.h>
using namespace std;
struct ListNode{
	int val;
	ListNode* next;
	ListNode(int x) : val(x),next(nullptr){}
	ListNode& operator=(const ListNode& r){
		this->val = r.val;
		this->next = r.next;
		return *this;
	}
};
int main(){
	int q;
	cin >> q;
	ListNode* head = new ListNode(1);
	ListNode* tail = head;
	while (q--){
		int op, x, y;
		cin >> op >> x;
		if (op == 1){
			cin >> y;
			ListNode* cur = head;
			while (cur && cur->val != x){
				cur = cur->next;
			}
			if (cur){
				ListNode* node = new ListNode(y);
				node->next = cur->next;
				cur->next = node;
				if(cur == tail){
					tail = node;
				}
			}
		}
		else if (op == 2) {
			ListNode* cur = head;
			while(cur && cur->val != x){
				cur = cur->next;
			}
			if (cur && cur->next){
				cout << cur->next->val << endl;
			}
			else{
				cout << "0" << endl;
			}
		}
		else if (op == 3){
			ListNode* cur = head;
			while(cur && cur->val != x){
				cur = cur->next;
			}
			if(cur && cur->next){
				ListNode* node = cur->next->next;
				*cur->next = *node;
				delete node;
				if (!cur->next) {
					tail = cur;
				}
			}
		}
	}
	return 0;
}

A了一个点,其他都RE,求调,必关

2025/7/2 16:56
加载中...