考察链表的知识,以及排序

题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1052

#include<iostream>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <algorithm>
using namespace std;typedef struct Node
{int curAdress, key, nextAdress;bool exist;Node(){exist = false;}bool operator < (const Node& orh) const{return key < orh.key;}
}Node;
#define MAX 1000000
int main()
{int n, root;scanf("%d%d",&n,&root);vector<Node> nodeMap(MAX);for (int i = 0; i < n; ++i){Node tmp;scanf("%d%d%d",&tmp.curAdress, &tmp.key, &tmp.nextAdress);tmp.exist = true;if(tmp.curAdress >= 0 && tmp.curAdress < MAX)nodeMap[tmp.curAdress] = tmp;}//processvector<Node> nodeList;int curID = root;while(curID >= 0 && curID < MAX && nodeMap[curID].exist){nodeList.push_back(nodeMap[curID]);curID = nodeMap[curID].nextAdress;}//outputif (nodeList.empty()){if (root == -1)printf("0 -1\n");else printf("0 %05d\n",root);}else{sort(nodeList.begin(), nodeList.end());printf("%d %05d\n", nodeList.size(), nodeList[0].curAdress);for (int i = 0; i < nodeList.size(); ++i){if(i != nodeList.size()-1)printf("%05d %d %05d\n", nodeList[i].curAdress, nodeList[i].key, nodeList[i+1].curAdress);else printf("%05d %d -1\n", nodeList[i].curAdress, nodeList[i].key);}}return 0;
}

1052. Linked List Sorting (25)相关推荐

  1. 1052 Linked List Sorting (25 分)

    Sample Input: 5 00001 11111 100 -1 00001 0 22222 33333 100000 11111 12345 -1 33333 22222 1000 12345 ...

  2. 【附段错误原因,最后两个测试点】1052 Linked List Sorting (25 分)【链表类题目总结】

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 A linked list consists of a series of structures, which are not n ...

  3. 1052 Linked List Sorting (25 分)【难度: 一般 / 知识点: 链表】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805425780670464 哈希表模拟链表. #include<b ...

  4. 1052 Linked List Sorting (25分)

    和 1074一样的方法,只需要管自己的结点就可以了,不需要处理next, 注意最后一个测试点,测试数据最终结果 为0个结点,只需要输出 0 -1 附本人AC代码: #include<iostre ...

  5. PAT甲级1052 Linked List Sorting:[C++题解]链表排序

    文章目录 题目分析 题目链接 题目分析 题意:给定数据(里面有不构成链表的数据,若是,则跳过),是链表的构成链表.然后根据数值大小重新排序,构成新的链表. 分析:用数组模拟链表,先建立链表.遍历链表, ...

  6. 1052. Linked List Sorting

    没仔细审题,走了很多弯路.题目要求:内存中有很多散列的节点,可能构成不止一个链表.其次要注意空链表的情况. // 1052. Linked List Sorting.cpp: 主项目文件.#inclu ...

  7. 1052 Linked List Sorting(排序)

    1052 Linked List Sorting(排序) 思路: s t r u c t + struct+ struct+排序. 坑点: 1.答案只包含从原链表中头结点开始的结点,有点结点不在原链表 ...

  8. PAT甲级1052:Linked List Sorting (25)

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

  9. 1052 Linked List Sorting 分数 25

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

最新文章

  1. 重载和覆盖的区别?(overload vs override)
  2. 最大调用堆栈大小超出错误
  3. cmake编译时支持gdb调试
  4. Docker创建私有仓库 | 数据卷和数据卷容器 | 容器互联 操作详解
  5. Android Studio打包和引用aar
  6. Javascript函数调用的四种方法
  7. linux下各目录的作用
  8. AFNetWorking 之 网络请求的基本知识
  9. ubuntu14.04 的网络配置
  10. Java将xml转docx,java对象与xml间的转换.docx
  11. php环境缺失msv文件_电脑环境缺失运行库_电脑缺失运行库
  12. 联想计算机wifi卸载,怎么卸载联想笔记本电源管理软件
  13. 免校准的电量计量芯片_免校准的高精度计量芯片HLW8032
  14. 基础回顾:10W+ 字 C 语言入门教程(上)
  15. cass等距离等分线段的命令键_cad直线均分的命令(CAD等分线段快捷键?)
  16. windows 商店的Ubuntu18.04安装教程
  17. 2018年(第17届)中国软件业务收入前百家企业名单
  18. 微信小程序开发技术介绍 有哪些?
  19. 大连二级及二级以上医保定点医院名单
  20. PyPi到底是什么?pypi有啥作用?PyPi和pip有何渊源?

热门文章

  1. mysql主从 复制新库_关于MySQL主从复制的几种复制方式总结
  2. 想知道留学同声传译app有哪些吗
  3. pandoc把word转为html,Latex转Word之间的转换(Pandoc+ latex2html 折中解决方案)
  4. JS原型链的一些理解
  5. 2023年第一批次申请考核制博士网上报名相关通知
  6. [转帖]关于USB3.0以及type-C
  7. 音频数据小波去噪-python
  8. windows下用bat文件启动带参数的bat文件的方法
  9. vue-qr二维码插件,vue 生成二维码
  10. Linux kswapd0进程CPU占用过高,病毒清理