当前位置:网站首页>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
边栏推荐
猜你喜欢

Idea is configured to connect to the remote database mysql, or Navicat fails to connect to the remote database (solved)

RPC procedure

Transformer XL: attention language modelsbbeyond a fixed length context paper summary

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

L2-3 浪漫侧影 (25 分)

00后最关注的职业:公务员排第二,第一是?

经典题目刷一刷

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

Notes on 30 steps of introduction to the Internet of things of yangtao electronics STM32 III. cubemx graphical programming and setting the IO port on the development board

根据字节码获取类的绝对路径
随机推荐
Judgment on heap (25 points) two insertion methods
K210 learning notes (II) serial communication between k210 and stm32
信息收集相关知识点及题解
Test your machine learning pipeline
DJ音乐管理软件Pioneer DJ rekordbox
rembg 分割mask
PLC的点表(寄存器地址和点表定义)破解探测方案--方便工业互联网数据采集
Large amount of data submitted by form post
Study notes of deep learning (8)
四张图弄懂matplotlib的一些基本用法
Get the absolute path of the class according to the bytecode
Latex paper typesetting operation
Add random attributes to the Li class array objects and sort them
RPC过程
Let the earth have less "carbon" and rest on the road
Idea is configured to connect to the remote database mysql, or Navicat fails to connect to the remote database (solved)
Restore binary tree (25 points)
使用flask和h5搭建网站/应用的简要步骤
洋桃电子STM32物联网入门30步笔记四、工程编译和下载
Shell script advanced