佬们救一下
  • 板块P1160 队列安排
  • 楼主mamou
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/8/24 14:25
  • 上次更新2024/8/24 16:20:28
查看原帖
佬们救一下
1029080
mamou楼主2024/8/24 14:25

一个刚学指针链表的蒟蒻写的 大佬们的题解都看不懂只能请教板块高手力(悲)

#include <bits/stdc++.h>
using namespace std;
struct Node{
	int no;
	Node *next,*last;
}*head; 
int main(){
	head=new(Node);
	head->no=0,head->next=NULL;
	Node *p=head;
	int n,m;
	cin>>n;
	for(int i=2;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		Node *q=new(Node);
		if(b==1){
			q->no=i,q->next=NULL;
			p->next=q,p=q;
		}
		else
		{
			q->no=i,q->last=NULL;
			p->last=q,p=q;
		}
	}
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		int a;
		cin>>a;
		for(Node *q=head->next;q!=NULL;q=q->next)
		{
			if(q->no==a)
			{
				(q-1)->next=q->next;
			}
		}
	}
	for(Node *q=head->next;q!=NULL;q=q->next)
	{
		cout<<q->no<<" ";
	}
	return 0;
}
2024/8/24 14:25
加载中...