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 & ...
随机推荐
- JAVA 自定义注解在自动化测试中的使用
在UI自动化测试中,相信很多人都喜欢用所谓的PO模式,其中的P,也就是page的意思,于是乎,在脚本里,或者在其它的page里,会要new很多的page对象,这样很麻烦,前面我们也讲到了注解的使用,很 ...
- SessionFactory 执行原生态的SQL语句
public List<User> getPageIndex(int pageIndex,int topNum){ String hql = "select top(" ...
- 【LeetCode-面试算法经典-Java实现】【062-Unique Paths(唯一路径)】
[062-Unique Paths(唯一路径)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 A robot is located at the top-left c ...
- C#-MVC开发微信应用(5)--自动应答系统-自动回复机器人
前几篇已经介绍菜单和有回复信息操作,下面我们就结合snf微信端管理页面,看一下什么才是自动应答系统. 定制的服务 对于微信服务号来说,最主要的功能是提供更好的服务.用户更方便的操作,以及更快的反馈响应 ...
- 在Pandas中更改列的数据类型【方法总结】
先看一个非常简单的例子: a = [['a', '1.2', '4.2'], ['b', '70', '0.03'], ['x', '5', '0']] df = pd.DataFrame(a) 有什 ...
- Node入门教程(12)第十章:Node的HTTP模块
Ryan Dahl开发node的初衷就是:把Nginx非阻塞IO功能和一个高度封装的WEB服务器结合在一起的东东.所以Node初衷就是为了高性能的Web服务器去的,所以:Node的HTTP模块也是核心 ...
- 基于jQuery图片遮罩滑动文字切换特效
基于jQuery图片遮罩滑动文字切换特效.这是一款jquery hover鼠标滑动选项卡切换透明背景遮罩文字显示特效.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div ...
- 【iCore1S 双核心板】DEMO V1.0 测试程序发布
iCore1S Demo V1.0程序说明 一.概要 本资料包含5个文件夹: 1.“ARM”里是iCore1S上ARM的程序包,开发环境为KEIL5.17: 2.“FPGA”里是iCore1S上FPG ...
- SaaS产品成功学
『精益』和『敏捷』之类的方法论在产品实现方面消除了不少浪费,但面对SaaS产品,这些却并没有像银弹般有效. 国外的『Ramen』团队模仿Maslow的需求层次理论提出了SaaS产品的需求层次理论,可以 ...
- React Native - FlexBox弹性盒模型
FlexBox布局 1. 什么是FlexBox布局? 弹性盒模型(The Flexible Box Module),又叫FlexBox,意为"弹性布局",旨在通过弹性的方式来对 ...