题目

1. 思路

  1. 使用map存放所有的地址对
  2. 使用起始地址遍历map,结果存放在vector中
  3. 排序vector
  4. 输出vector

2. 注意点

  1. 开始的时候起始地址为-1
  2. 可能有些节点没有用到,注意排除

3. 代码

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iostream>
using namespace std; struct node{
string add;
int score;
node(string _add, int _score){
add = _add;
score = _score;
}
}; bool cmp(node a, node b) {
return a.score < b.score;
} void print(vector<node> s){
int i=0;
for(i=0;i<s.size()-1;i++){
printf("%s %d %s\n", s[i].add.c_str(), s[i].score, s[i+1].add.c_str());
}
printf("%s %d -1", s[i].add.c_str(), s[i].score);
} int main() {
vector<node> list;
map<string, pair<string, int> > mp;
int n;
char start[10];
scanf("%d %s", &n, start);
for(int i=0;i<n;i++){
char a[10], b[10];
int num;
scanf("%s %d %s", a, &num, b);
mp[string(a)] = make_pair(string(b), num);
}
string _start = start;
if(_start == "-1"){
printf("0 -1");
return 0;
}
while(_start != "-1"){
pair<string, int> p = mp[_start];
list.push_back(node(_start, p.second));
_start = p.first;
}
sort(list.begin(), list.end(), cmp);
printf("%d %s\n", list.size(), list[0].add.c_str());
print(list);
}

1052 Linked List Sorting (25分)的更多相关文章

  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 分)

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

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

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

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

  5. Pat 1052 Linked List Sorting (25)

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

  6. 1052. Linked List Sorting (25)

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

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

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

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

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

  9. PAT (Advanced Level) 1052. Linked List Sorting (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

随机推荐

  1. opencv —— floodFill 漫水填充法 实现证件照换背景

    漫水填充:floodFill 函数 简单来说,漫水填充就是自动选中与种子像素相连的区域,利用指定颜色进行区域颜色填充.Windows 画图工具中的油漆桶功能和 Photoshop 的魔法棒选择工具,都 ...

  2. sass实现头条新闻列表页面

    Index.html <!DOCTYPE html> <html> <head> <title>今日头条</title> <meta ...

  3. 基于Docker的Consul集群实现服务发现

    服务发现 其实简单说,服务发现就是解耦服务与IP地址之间的硬绑定关系,以典型的集群为例,对于集群来说,是有多个节点的,这些节点对应多个IP(或者同一个IP的不同端口号),集群中不同节点责任是不一样的. ...

  4. P3902 递增

    链接:P3902 ----------------------------------------- 这道题就是最长上升子序列的模板题,因为我们修改的时候可没说不能改成小数(暴力) --------- ...

  5. 第6章.BitArray类

    参考链接: https://www.cnblogs.com/wang7/archive/2012/04/13/2446353.html https://www.runoob.com/csharp/cs ...

  6. ubuntu 1804 rsync 命令 服务端配置

    1. rsync的主要作用 rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.rsync使用所谓的"rsync算法"来使本地和远程两个主机之间的文 ...

  7. javaSE学习笔记(10)---List、Set

    javaSE学习笔记(10)---List.Set 1.数据存储的数据结构 常见的数据结构 数据存储的常用结构有:栈.队列.数组.链表和红黑树. 1.栈 栈:stack,又称堆栈,它是运算受限的线性表 ...

  8. HTML5音频(自定义mp3播放器源码)

    audio对象 src兼容.ogg .wav .mp3 <audio controls src='data/imooc.wav'></audio> width autoplay ...

  9. kali linux中mariadb加上密码

    kali自带mysql.2019.4 中带得是:MariaDB.据说跟Mysql差不多.简单用了一下发现root用户可以不要密码进入Mysql! 这极不习惯,不输入密码感觉好像少了点什么.这肯定是权限 ...

  10. 关于Comparable和Comparator那些事

    在实际项目开发过程中,我们经常需要对某个对象或者某个集合中的元素进行排序,常用的两种方式是实现某个接口.常见的可以实现比较功能的接口有Comparable接口和 Comparator接口,那么这两个又 ...