PAT a1052题解
来源:互联网 发布:上海淘宝厂家 编辑:程序博客网 时间:2024/05/16 14:04
#include <cstdio>#include <algorithm>using namespace std;const int maxn = 100005;struct Node{int address, data, next;bool flag;}node[maxn]; bool cmp(Node a, Node b){ if(a.flag == false || b.flag == false){ return a.flag > b.flag; } else{ return a.data < b.data; } } int main(){ for(int i = 0; i < maxn; i++){ node[i].flag = false; } int n, begin, address; scanf("%d%d", &n, &begin); for(int i = 0; i < n; i++){ scanf("%d", &address); scanf("%d%d", &node[address].data, &node[address].next);node[address].address = address; } int count = 0, p = begin; while(p != -1){ node[p].flag = true; count++; p = node[p].next; } if(count == 0){ printf("0 -1"); } else{ sort(node, node + maxn, cmp);printf("%d %05d\n", count, node[0].address);for(int i = 0; i < count; i++){if(i != count - 1){printf("%05d %d %05d\n", node[i].address, node[i].data, node[i + 1].address);}else{printf("%05d %d -1\n", node[i].address, node[i].data);}} } return 0; }
阅读全文
1 0
- PAT a1052题解
- PAT-A1052
- PAT A1052. Linked List Sorting (25)
- pat-a1052. Linked List Sorting (25)
- PAT 1001-1010 题解
- PAT 1011-1020 题解
- PAT 1021-1030 题解
- PAT 1031-1040 题解
- PAT 1041-1050 题解
- PAT 1051-1060 题解
- PAT(basic level)题解
- PAT乙级题解
- PAT题解目录
- PAT甲级题解目录
- PAT乙级题解目录
- PAT甲级1001题解
- PAT甲级1002题解
- PAT b1001-1005题解
- ‘XXXX’ was compiled with optimization
- Matlab常用概率密度函数、累计概率分布函数及其逆函数
- Flink学习笔记 --- 研究 FlinkForward2017 源码
- POJ #1186 方程的解数 | 中途相遇法 + Hash | 解题报告
- PAT a1051题解
- PAT a1052题解
- 自定义表格控件
- 信号槽如何传递参数
- Nginx80端口转发+域名——实现IP+端口隐藏
- 第2章 渲染流水线
- PAT a1053题解
- 端口映射怎么设置
- Matlab如何真正自如的控制legend
- bzoj 3886: [Usaco2015 Jan]Moovie Mooving 状压dp