当前位置:网站首页>L2-022 rearrange linked list (25 points) (map + structure simulation)
L2-022 rearrange linked list (25 points) (map + structure simulation)
2022-04-23 08:44:00 【.Ashy.】
describe :

Input :
Each input contains 1 Test cases . Each test case is No 1 Line gives 1 Address of nodes and total number of nodes , Positive integer N ≤105). The address of the node is 5 Bit nonnegative integer ,NULL Address use −1 Express .
Next there is N That's ok , The format of each line is :
Address Data Next
among Address Is the node address ;Data Is the data saved in this node , For no more than 10 5
The positive integer ;Next Is the address of the next node . The title ensures that there are at least two nodes in the list .
Output :
For each test case , Output the rearranged result list in sequence , Each node on it occupies a row , The format is the same as the input .
The sample input :
00100 6
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218
Sample output :
68237 6 00100
00100 1 99999
99999 5 12309
12309 2 00000
00000 4 33218
33218 3 -1
Be careful :
Test point 31 started wrong , Give it a try , It is found that there is invalid data not in the linked list in the given address data , Correct it ;
/* 00100 6 00000 4 99999 00100 1 12309 33218 3 00000 99999 5 -1 12309 2 33218 sssss 6 sssss// Invalid data test */
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll maxx = 1e18;
const int N = 1e6+100;
const int ps = 1e4+10;
const double eps = 1e-8;
string s1,ss;
int n,cnt;
pair<int,string>p;
map<string,pair<int,string>>mp;
struct node{
string adds;
int k;
}a[N];
int main()
{
cin>>s1>>n;
for(int i=1;i<=n;i++)
{
cin>>ss>>p.first>>p.second;
mp[ss]=p;
}// Record information
while(s1!="-1")
{
a[++cnt].adds=s1;
a[cnt].k=mp[s1].first;
s1=mp[s1].second;
}// Store information in the structure
n=cnt;// hold n Replace with the effective number
if(n%2==0)
{
for(int i=1;i<=n/2;i++)
{
cout<<a[n-i+1].adds<<" "<<a[n-i+1].k<<" ";
cout<<a[i].adds<<endl<<a[i].adds<<" "<<a[i].k<<" ";
if(i!=n/2)
cout<<a[n-i].adds<<endl;
else
cout<<"-1";
}
}
else
{
for(int i=1;i<=n/2;i++)
{
cout<<a[n-i+1].adds<<" "<<a[n-i+1].k<<" ";
cout<<a[i].adds<<endl<<a[i].adds<<" "<<a[i].k<<" ";
cout<<a[n-i].adds<<endl;
}
cout<<a[n/2+1].adds<<" "<<a[n/2+1].k<<" "<<"-1";
}
}// Output... In sequence
版权声明
本文为[.Ashy.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230842481794.html
边栏推荐
- 是否同一棵二叉搜索树 (25 分)
- 完全二叉搜索树 (30 分)
- After a circle, I sorted out this set of interview questions..
- idea底栏打开services
- Yangtao electronic STM32 Internet of things entry 30 step notes IV. engineering compilation and download
- Queue (C language / linked list)
- 共享办公室,提升入驻体验
- Use include in databinding
- Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing
- 测试你的机器学习流水线
猜你喜欢

flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】

ONEFLOW learning notes: from functor to opexprinter

正点原子携手OneOS直播 OneOS系统教程全面上线

JVM工具之Arthas使用

洋桃电子STM32物联网入门30步笔记三、CubeMX图形化编程、设置开发板上的IO口

Let the earth have less "carbon" and rest on the road

Automatic differentiation and higher order derivative in deep learning framework

On time atom joins hands with oneos live broadcast, and the oneos system tutorial is fully launched

汇编语言与逆向工程 栈溢出漏洞逆向分析实验报告

STM32使用HAL库,整体结构和函数原理介绍
随机推荐
1099 建立二叉搜索树 (30 分)
Navicat remote connection MySQL
HAL库的RCC简介
使用flask和h5搭建网站/应用的简要步骤
Output first order traversal according to second order and middle order traversal (25 points)
rembg 分割mask
Latex mathematical formula
在sqli-liabs学习SQL注入之旅(第十一关~第二十关)
Stm32f103zet6 [development of standard library functions] - Introduction to library functions
Knowledge points and problem solutions related to information collection
idea底栏打开services
Complete binary search tree (30 points)
信息收集相关知识点及题解
基于点云凸包的凹包获取方法
Restore binary tree (25 points)
Automatic differentiation and higher order derivative in deep learning framework
还原二叉树 (25 分)
L2-3 浪漫侧影 (25 分)
Go语言自学系列 | golang方法
PDF with watermark