当前位置:网站首页>L2-022 重排链表 (25 分)(map+结构体模拟)
L2-022 重排链表 (25 分)(map+结构体模拟)
2022-04-23 08:43:00 【.Ashy.】
描述:

输入:
每个输入包含1个测试用例.每个测试用例第1行给出第1个结点的地址和结点总个数,即正整数N ≤105)。结点的地址是5位非负整数,NULL地址用−1表示。
接下来有N行,每行格式为:
Address Data Next
其中Address是结点地址;Data是该结点保存的数据,为不超过10 5
的正整数;Next是下一结点的地址。题目保证给出的链表上至少有两个结点。
输出:
对每个测试用例,顺序输出重排后的结果链表,其上每个结点占一行,格式与输入相同。
样例输入:
00100 6
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218
样例输出:
68237 6 00100
00100 1 99999
99999 5 12309
12309 2 00000
00000 4 33218
33218 3 -1
注意:
测试点三一开始错了,试了试,发现给出的地址数据中有不在链表中的无效数据,改正一下;
/* 00100 6 00000 4 99999 00100 1 12309 33218 3 00000 99999 5 -1 12309 2 33218 sssss 6 sssss//无效数据测试 */
#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;
}//记录信息
while(s1!="-1")
{
a[++cnt].adds=s1;
a[cnt].k=mp[s1].first;
s1=mp[s1].second;
}//把信息存到结构体中
n=cnt;//把 n 换成有效个数
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";
}
}//依次输出
版权声明
本文为[.Ashy.]所创,转载请带上原文链接,感谢
https://blog.csdn.net/woshilichunyang/article/details/124357315
边栏推荐
- Protobuf简介
- HAL库的RCC简介
- idea配置连接远程数据库MySQL,或者是Navicat连接远程数据库失败问题(已解决)
- Idea is configured to connect to the remote database mysql, or Navicat fails to connect to the remote database (solved)
- 正点原子携手OneOS直播 OneOS系统教程全面上线
- Add listening event to input element
- 1099 establish binary search tree (30 points)
- 根据字节码获取类的绝对路径
- Noyer électronique stm32 Introduction à l'Internet des objets 30 étapes notes I. différences entre la Bibliothèque Hal et la Bibliothèque standard
- 请问中衍期货安全靠谱吗?
猜你喜欢
随机推荐
LINQ Learning Series ----- 1.4 anonymous objects
匿名类型(C# 指南 基础知识)
Virtual online exhibition - Online VR exhibition hall realizes 24h immersive exhibition viewing
引用传递1
K210 learning notes (II) serial communication between k210 and stm32
单片机数码管秒表
okcc呼叫中心外呼系统智能系统需要用多大的盘存录音?
企业微信应用授权/静默登录
Judgment on heap (25 points) two insertion methods
Queue (C language / linked list)
玩转二叉树 (25 分)
DJ音乐管理软件Pioneer DJ rekordbox
Introduction to protobuf
洋桃电子STM32物联网入门30步笔记一、HAL库和标准库的区别
Stm32f103zet6 [development of standard library functions] - Introduction to library functions
How much inventory recording does the intelligent system of external call system of okcc call center need?
'恶霸' Oracle 又放大招,各大企业连夜删除 JDK。。。
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
Let the earth have less "carbon" and rest on the road
L2-3 romantic silhouette (25 points)









