当前位置:网站首页>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
边栏推荐
- Flash project cross domain interception and DBM database learning [Baotou cultural and creative website development]
- Protobuf简介
- SYS_ CONNECT_ BY_ Path (column, 'char') combined with start with connect by prior
- 搜索树判断 (25 分)
- Go语言自学系列 | golang结构体的初始化
- 测试你的机器学习流水线
- IDEA导入commons-logging-1.2.jar包
- 1099 establish binary search tree (30 points)
- Enctype attribute in form
- 怎样读取Excel表格到数据库
猜你喜欢
RCC introduction of Hal Library
深度学习框架中的自动微分及高阶导数
Noyer électronique stm32 Introduction à l'Internet des objets 30 étapes notes I. différences entre la Bibliothèque Hal et la Bibliothèque standard
After a circle, I sorted out this set of interview questions..
【58】最后一个单词的长度【LeetCode】
pgsql想实现mysql一样样的列子查询操作
经典题目刷一刷
Let the earth have less "carbon" and rest on the road
洋桃电子STM32物联网入门30步笔记一、HAL库和标准库的区别
Yangtao electronic STM32 Internet of things entry 30 step notes IV. engineering compilation and download
随机推荐
Protobuf简介
Yangtao electronic STM32 Internet of things introduction 30 steps notes 1. The difference between Hal library and standard library
Go语言自学系列 | golang方法
Use of Arthas in JVM tools
synchronized 锁的基本用法
Idea import commons-logging-1.2 Jar package
LaTeX论文排版操作
Whether the same binary search tree (25 points)
PLC的点表(寄存器地址和点表定义)破解探测方案--方便工业互联网数据采集
洋桃电子STM32物联网入门30步笔记一、HAL库和标准库的区别
LLVM之父Chris Lattner:编译器的黄金时代
Use include in databinding
Queue (C language / linked list)
洋桃电子STM32物联网入门30步笔记四、工程编译和下载
Excle plus watermark
请问中衍期货安全靠谱吗?
Transformer XL: attention language modelsbbeyond a fixed length context paper summary
Complete binary search tree (30 points)
K210 learning notes (II) serial communication between k210 and stm32
怎样读取Excel表格到数据库