1133 Splitting A Linked List (25 分)【难度: 一般 / 知识点: 链表模拟】

在这里插入图片描述
https://pintia.cn/problem-sets/994805342720868352/problems/994805346776760320

#include<bits/stdc++.h>
using namespace std;
int startx,n,k;
map<int,int>hush,val,ne;
vector<pair<int,int>> ve,ans;
int main(void)
{
    
    
	cin>>startx>>n>>k;
	for(int i=0;i<n;i++)
	{
    
    
		int a,b,c; cin>>a>>b>>c;
		val[a]=b,ne[a]=c;
	}
	while(startx!=-1)
	{
    
    
		int id=startx,s=val[startx];
		if(startx>=0) ve.push_back({
    
    id,s});
		startx=ne[startx];
	}
	for(int i=0;i<ve.size();i++) 
	if(ve[i].second<0) hush[ve[i].first]=1,ans.push_back(ve[i]);
	
	for(int i=0;i<ve.size();i++) 
	if(ve[i].second>=0&&ve[i].second<=k)hush[ve[i].first]=1,ans.push_back(ve[i]);
	
	for(int i=0;i<ve.size();i++)	
	if(!hush[ve[i].first]) ans.push_back(ve[i]);
	
	for(int i=0;i<ans.size();i++)
	{
    
    
		if(i==ans.size()-1) printf("%05d %d %d",ans[i].first,ans[i].second,-1);
		else printf("%05d %d %05d\n",ans[i].first,ans[i].second,ans[i+1].first);
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/qq_46527915/article/details/121548588