题目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的更多相关文章

  1. PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)

    1052 Linked List Sorting (25 分)   A linked list consists of a series of structures, which are not ne ...

  2. 【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 ...

  3. PAT甲级——A1052 Linked List Sorting

    A linked list consists of a series of structures, which are not necessarily adjacent in memory. We a ...

  4. PAT Advanced 1052 Linked List Sorting (25) [链表]

    题目 A linked list consists of a series of structures, which are not necessarily adjacent in memory. W ...

  5. PAT 解题报告 1052. Linked List Sorting (25)

    1052. Linked List Sorting (25) A linked list consists of a series of structures, which are not neces ...

  6. PAT 1052 Linked List Sorting [一般]

    1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not nece ...

  7. Pat 1052 Linked List Sorting (25)

    1052. Linked List Sorting (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A ...

  8. 【PAT甲级】1052 Linked List Sorting (25 分)

    题意: 输入一个正整数N(<=100000),和一个链表的头结点地址.接着输入N行,每行包括一个结点的地址,结点存放的值(-1e5~1e5),指向下一个结点的地址.地址由五位包含前导零的正整数组 ...

  9. PAT甲题题解-1052. Linked List Sorting (25)-排序

    三个注意点: 1.给出的n个节点并不一定都在链表中 2.最后一组样例首地址即为-1 3.输出地址的时候一直忘记前面要补0... #include <iostream> #include & ...

随机推荐

  1. 〖Android〗我的ADT Eclipse定制

    1. 配置自动补全: Windows -> preferences -> 搜索assist,修改 java xml自动触发补全:.abcdefghijklmnopqrstuvwxyzABC ...

  2. MySQL 四种事务隔离级的说明[转]

    很早之前写的文章,重新回顾和学习下: 按照SQL:1992 事务隔离级别,InnoDB默认是可重复读的(REPEATABLE READ).MySQL/InnoDB 提供SQL标准所描述的所有四个事务隔 ...

  3. Atitit web remote远程调试的原理attilax总结

    Atitit web remote远程调试的原理attilax总结 Jvm是vm打开一个debug port,然后ide先连接..然后执行url,就会vm会与ide沟通.. Php的xdebug po ...

  4. vs get set快捷键

    vs get set快捷键 光标放在空白处输入prop,然后tab两次,修改类型和名称即可

  5. 4. Tensorflow的Estimator实践原理

    1. Tensorflow高效流水线Pipeline 2. Tensorflow的数据处理中的Dataset和Iterator 3. Tensorflow生成TFRecord 4. Tensorflo ...

  6. CAD技巧之002——如何用Cass内插高程点或者说加密高程点

    CAD技巧之002——如何用Cass内插高程点或者说加密高程点 很多同志如果遇到奇葩的Cass内插高程点或者说加密高程点,怎么办,一个个编辑?如果工作量很大,怎么办呢. 今天九天就教您一个好方法! 废 ...

  7. FPGA编程—组合逻辑编码器等verilog实现

    本篇博客主要实现对组合逻辑电路的一些常用模块的实现.组合逻辑中,包括译码器,编码器,输入输出选择器,数值比较器,算法单元等.  先来实现编码器,最常用的8-3编码器,这里先讲一下要用到的case ,c ...

  8. linux-centos下持续集成工具jenkins部署使用教程

    centos下准备工作: 1.安装jdk环境 2.安装maven环境(用于构建项目) 3.git客户端(用于拉取源码) 此外码云还要准备一份java源码(springboot项目) 一.安装jenki ...

  9. spark 解析非结构化数据存储至hive的scala代码

    //提交代码包 // /usr/local/spark/bin$ spark-submit --class "getkv" /data/chun/sparktes.jar impo ...

  10. 【QT】打开文件对话框,选择路径下文件

    0.头文件中加入 public: QString fileName; public slots: void showImage(); 1.添加两个头文件 #include<qfiledialog ...