20分,其余全RE
查看原帖
20分,其余全RE
1137661
maple23333楼主2023/12/10 19:57
#include<stdio.h>
#include<stdlib.h>

struct node
{
	int data;
	struct node* next;
};
int str[1000005][20];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &str[i][0]);
		if (str[i][0] == 1)
			scanf("%d %d", &str[i][1], &str[i][2]);
		else
			scanf("%d", &str[i][1]);
	}
		
	struct node* head, * newp, * now;
	newp = (struct node*)malloc(sizeof(struct node));
	(*newp).data = 1;
	head = newp;
	now = newp;
	now->next = 0;
	for (int i = 0; i < n; i++) {

		if (str[i][0] == 1) {
			newp = (struct node*)malloc(sizeof(struct node));
			(*newp).data = str[i][2];
			
			if (str[i][1]==now->data) {
				now->next = newp;
				now = newp;
			}
			else {
				struct node* p = head;
				while (p->data != str[i][1]) {
					p = p->next;
				}
				newp->next = p->next;
				p->next = newp;
			}
		}now->next = 0;
		if (str[i][0] == 2) {
			newp = (struct node*)malloc(sizeof(struct node));
			newp->data = str[i][1];
			struct node* p = head;
			while (p->data != newp->data) {
				p = p->next;
			}
			p = p->next;
			printf("%d\n", p->data);
		}
		if (str[i][0] == 3) {
			newp = (struct node*)malloc(sizeof(struct node));
			newp->data = str[i][1];
			struct node* p = head;
			while (p->data != newp->data) {
				now = p;
				p = p->next;
			}
			p = p->next;
			now = p;
			now->next = p->next;
			free(p);
		}
	}now->next = 0;
	
	return 0;
}
2023/12/10 19:57
加载中...