当前位置:网站首页>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
边栏推荐
- IDEA导入commons-logging-1.2.jar包
- Input / output system
- LINQ Learning Series ----- 1.4 anonymous objects
- 2021李宏毅机器学习之Adaptive Learning Rate
- Detailed description of self feeling of auricular point weight loss 0422
- Anonymous type (c Guide Basics)
- Go语言自学系列 | golang结构体指针
- 是否同一棵二叉搜索树 (25 分)
- php基于哈希算法出现的强弱比较漏洞
- Kubernetes如何使用harbor拉去私有镜像
猜你喜欢
随机推荐
匿名类型(C# 指南 基础知识)
Whether the same binary search tree (25 points)
bashdb下载安装
How much inventory recording does the intelligent system of external call system of okcc call center need?
增强现实技术是什么?能用在哪些地方?
Introduction to protobuf
Get the absolute path of the class according to the bytecode
OneFlow學習筆記:從Functor到OpExprInterpreter
Go语言自学系列 | golang嵌套结构体
dataBinding中使用include
Shell script advanced
JSP page coding
After a circle, I sorted out this set of interview questions..
Reference passing 1
Ear acupoint diagnosis and treatment essay 0421
LeetCode396.旋转数组
ONEFLOW learning notes: from functor to opexprinter
Kubernetes如何使用harbor拉去私有镜像
Automatic differentiation and higher order derivative in deep learning framework
使用flask和h5搭建网站/应用的简要步骤









