当前位置:网站首页>PAT甲级 1052 Linked List Sorting
PAT甲级 1052 Linked List Sorting
2022-08-08 00:53:00 【九是否非随机的称呼】
要注意存在非链路节点,或者不存在结尾节点也就是不存在 -1
#include<iostream>
#include<vector>
#include<map>
#include<bits/stdc++.h>
using namespace std;
typedef struct {
string address;
string nextes;
int val;
} linked;
bool compare(const linked& lhs, const linked& rhs){
if(lhs.val <= rhs.val) return true;
else return false;
}
int main(void){
int i, j, k, m, n, h, mm, nn;
string s;
cin>>m>>s;
linked lkd;
vector<linked> v, v0;
map<string, int> mp;
h = -9999999;
for(i = 0; i < m; i++){
cin>>lkd.address>>lkd.val>>lkd.nextes;
if(lkd.address==s) h = i;
mp[lkd.address] = i;
v.push_back(lkd);
}
if(h < 0){
cout<<"0 -1"<<endl;
return 0;
}
lkd = v[h];
v0.push_back(lkd);
string con = "-1";
while(lkd.nextes!=con){
lkd = v[mp[lkd.nextes]];
v0.push_back(lkd);
}
v=v0;
sort(v.begin(), v.end(), compare);
cout<<v.size()<<" "<<v[0].address<<endl;
for(i=0; i<v.size()-1; i++){
cout<<v[i].address<<" "<<v[i].val<<" "<<v[i+1].address<<endl;
}
cout<<v[v.size()-1].address<<" "<<v[v.size()-1].val<<" "<<"-1";
return 0;
}边栏推荐
- 激光雷达战场越来越激烈了
- RT-Thread uses arm_math
- 【PHP库】phpseclib - sftp远程文件操作
- leetcode 30. 串联所有单词的子串
- MySQL笔记-05 数据表操作
- win10 rdkit下载及使用
- Stack SQL injection, rounding
- Good news | Hongshi data has obtained CMMI level 3 certification!Welcome to the self-developed unified operation and maintenance monitoring platform!
- Introduction and detailed explanation of OpenFeign
- Octopus Application Chain|Content Curation Collaboration Organization DISCOVOL DAO Mainnet Launched in August
猜你喜欢
随机推荐
带你刷(牛客网)C语言百题(第五天)
JS中常用的数组方法(补充)
使用jmh框架进行benchmark测试
陈强教授《机器学习及R应用》课程 第八章作业
深度解读 Vite 的依赖扫描?
pycharm连接远程服务器
立秋是中稻收割的日子
陈强教授《机器学习及R应用》课程 第十章作业
Leetcode.86 分隔链表(使用哑结点模拟)
Shell脚本中常用命令复习
《MySQL入门很轻松》第2章:MySQL管理工具介绍
Flexible and easy-to-use sql monitoring script part6
像素画家KIN作品欣赏
继承关系下构造方法的访问特点注意:把this()访问本类其他成员方法也加进去
高数_证明_罗尔定理
Distributed agreement of Lease mechanism
textplot包:文本语义及可视化
MySQL笔记-05 数据表操作
Stack SQL injection, rounding
部署spark2.2集群(standalone模式)
https://github.com/ZouJiu1/PAT








