题目

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. go单任务版爬虫

    go单任务版爬虫(爬取珍爱网) 爬虫总体算法 单任务版爬虫架构 任务 获取并打印所在城市第一页用户的详细信息 代码实现 /crawler/main.go package main import ( & ...

  2. django-分页(非海量数据)

    views.py class AnalysisDataHandler(View): def get(self, request): analysis_data = MonitorCenterDataA ...

  3. java 开发中 dom4j的简单用法

    Java中处理XML的方式有很多种,个人任务dom4j还是比较好用的.下面介绍以下简单的使用方法 先把import补充上 import org.dom4j.Document; import org.d ...

  4. C# WPF 时钟动画(1/2)

    微信公众号:Dotnet9,网站:Dotnet9,问题或建议:请网站留言, 如果对您有所帮助:欢迎赞赏. C# WPF 时钟动画(1/2) 内容目录 实现效果 业务场景 编码实现 本文参考 源码下载 ...

  5. 如何将博客搬至CSDN

    简单聊下对于博客园的印象是技术改变世界,作为一个IT技术人员很乐意把这里当作自己的网上家园,每天在这里分享着精彩的原创内容,看重的不是华丽的外表.诱人的虚名,而是纯净.专注.对技术人员的理解. CSD ...

  6. Linux学习笔记:磁盘分区

    本文更新于2019-12-30.操作系统为Debian 8.9 (jessie). 以下假设新磁盘为/dev/sdb,要创建一个分区/dev/sdb1,文件系统类型为xfs.请根据实际情况,自行选择. ...

  7. centos7安装显示中文

    系统通过环境变量LANG设置语言格式编码 查看当前语言环境 echo $LANG 查看是否安装中文语言,Linux中通过locale来设置程序运行的不同语言环境 locale -a | grep 'z ...

  8. 剑指offer-面试题10-斐波那契数列-递归循环

    /* 题目:求斐波那契数列的第n项 */ /* 思路: f(n) = 0 n=0, 1 n=1, f(n-1) + f(n-2) n>1 */ int Fibonacci(int n){ if( ...

  9. 04-SV连接设计和测试平台

    1.验证一个设计的步骤: 生成输入激励,捕捉输出响应,决定对错和进度 2.连接设计和测试平台 信号连接:SystemVerilog已经扩展了传统的reg类型,可以像wire那样用来连接模块,它的新名字 ...

  10. C# 一次循环获取树的两种方法

    第一种方法好些 第二种方法如果中间断开就会成为一级 private static List<Menu> MenuTree() { , ParentId = , Name = "a ...