代码在本地可实现题目要求,但全wa!求调!!感谢!!
查看原帖
代码在本地可实现题目要求,但全wa!求调!!感谢!!
733691
linyisu楼主2024/8/5 21:15

各位大犇求帮忙康康代码!!谢谢!!!!!

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); 
using namespace std;

struct node{
	int val;
	struct node* next;
};

void insertNode(int x, int y, node* head)
{
	node* nod = (node*)malloc(sizeof(node));
	nod->val = y;
	nod->next = NULL;
	while (head->next && head->val != x)
		head = head->next;
	head->next = nod;
}

void askNode(int x, node* head)
{
	while (head->next && head->val != x)
		head = head->next;
	if (head->next == NULL)
		cout << "0" << "\n";
	else
		cout << head->next->val << "\n";
}

void eraseNode(int x, node* head)
{
	while (head->next && head->val != x)
		head = head->next;
	if (head->next)
		head->next = head->next->next;
}

int main()
{
	IOS;
	int n;
	cin >> n;
	int op, x, y;
	
	node* nod = (node*)malloc(sizeof(node));
	nod->val = 1;
	nod->next = NULL;
	
	for (int i=0;i<n;i++)
	{
		cin >> op;
		switch (op)
		{
			case 1:
				cin >> x >> y; 
				insertNode(x, y, nod);
				break;
			case 2:
				cin >> x;
				askNode(x, nod);
				break;
			case 3:
				cin >> x;
				eraseNode(x, nod);
				break;
		}
	}
	return 0;
}
2024/8/5 21:15
加载中...