PAT甲级1052 Linked List Sorting
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805425780670464
题意:
给定一些内存中的节点的地址,值以及下一节点所在地址。
要求对给定的头指针表示的链表进行排序。
思路:
PAT的题目小细节真的很多啊。这道题要注意有可能有的节点是不在头指针链成的链表里的。
所以要先遍历一次链表,然后再排序。
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue> #define inf 0x7fffffff
using namespace std;
typedef long long LL;
typedef pair<string, string> pr; int n, head;
struct node{
int key;
int nxt;
}l[];
struct num{
int add;
int key;
}tmp[]; bool cmp(num a, num b)
{
return a.key < b.key;
} int main()
{
scanf("%d%d", &n, &head);
for(int i = ; i < n; i++){
int a;
scanf("%d", &a);
scanf("%d%d", &l[a].key, &l[a].nxt);
} int now = head;
int cnt = ;
while(now != -){
tmp[cnt].add = now;
tmp[cnt].key = l[now].key;
now = l[now].nxt;
cnt++;
}
sort(tmp, tmp + cnt, cmp);
if(cnt == ){
printf("0 -1\n");
}
else{
printf("%d %05d\n", cnt, tmp[].add);
for(int i = ; i < cnt - ; i++){
printf("%05d %d %05d\n", tmp[i].add, tmp[i].key, tmp[i + ].add);
}
printf("%05d %d -1\n", tmp[cnt - ].add, tmp[cnt - ].key);
} return ;
}
PAT甲级1052 Linked List Sorting的更多相关文章
- PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)
1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not ne ...
- 【PAT】1052 Linked List Sorting (25)(25 分)
1052 Linked List Sorting (25)(25 分) A linked list consists of a series of structures, which are not ...
- PAT甲级——A1052 Linked List Sorting
A linked list consists of a series of structures, which are not necessarily adjacent in memory. We a ...
- PAT Advanced 1052 Linked List Sorting (25) [链表]
题目 A linked list consists of a series of structures, which are not necessarily adjacent in memory. W ...
- PAT 解题报告 1052. Linked List Sorting (25)
1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...
- PAT 1052 Linked List Sorting [一般]
1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not nece ...
- Pat 1052 Linked List Sorting (25)
1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...
- 【PAT甲级】1052 Linked List Sorting (25 分)
题意: 输入一个正整数N(<=100000),和一个链表的头结点地址.接着输入N行,每行包括一个结点的地址,结点存放的值(-1e5~1e5),指向下一个结点的地址.地址由五位包含前导零的正整数组 ...
- PAT甲题题解-1052. Linked List Sorting (25)-排序
三个注意点: 1.给出的n个节点并不一定都在链表中 2.最后一组样例首地址即为-1 3.输出地址的时候一直忘记前面要补0... #include <iostream> #include & ...
随机推荐
- JDK自带的运行监控工具JConsole观察分析Java程序的运行
原文地址:https://blog.csdn.net/libaolin198706231987/article/details/55057149 一.JConsole是什么 从Java 5开始 引入了 ...
- Nginx负载均衡权重,ip_hash
nginx为后端web服务器(apache,nginx,tomcat,weblogic)等做反向代理 几台后端web服务器需要考虑文件共享,数据库共享,session共享问题.文件共享可以使用nfs, ...
- MySQL在线删除多余的binlog文件
如果你的MySQL搭建了主从同步 , 或者数据库开启了log-bin日志(MySQL默认开启) , 那么随着时间的推移 , 你的数据库data 目录下会产生大量的日志文件 ll /opt/mysql/ ...
- ajax请求中的6个全局事件
//事件触发顺序ajaxStart,ajaxSend,ajaxSuccess或ajaxError,ajaxComplete,ajaxStop $(document).ajaxStart(functio ...
- linux每日命令(10):touch命令
linux的touch命令一般用来修改文件时间戳,或者新建一个不存在的文件. 一.命令格式: touch [参数]... 文件... 二.命令参数: 参数 描述 -a 或--time=atime或-- ...
- WebMisSharp更新了,最新版本1.5.2,WebMisCentral-Client最新版
WebMisSharp更新记录 Version 1.5.2 1.5.2下载地址:http://item.taobao.com/item.htm?spm=686.1000925.1000774.13.w ...
- Git 补丁操作
补丁是文本文件,其内容是相似于Git diff,但随着代码,它也有元数据有关提交,如提交ID,日期,提交信息等,我们可以创建补丁提交和其他人可以将它们应用到自己的资料库. Jerry 为他们的项目实现 ...
- MyBatis XML转义字符
当我们需要通过xml格式处理sql语句时,经常会用到< ,<=,>,>=等符号,但是很容易引起xml格式的错误,这样会导致后台将xml字符串转换为xml文档时报错,从而导致程序 ...
- 奇淫怪巧之在Delphi中调用不申明函数
前一阵子,研究了一段时间的Win32Asm,研究到后来发现Win32的ASM实际上还是和C版的介绍的一样.甚至还封装了一个简版的类似VCL库结构框架的32ASM结构库,不过搞着搞着就没兴趣了,也没继续 ...
- SAP HANA S4 FI TABLE表结构
一.统一日记账的表 1)一个行项目表,存储所有应用的全部明细–迅速获得洞察力和扩展能力; 2)次级成本要素也变成了总账科目,统一入口维护和管理; 3)数据只需存储一次在一张表,不需要再做月末对账,如A ...