【PAT甲级】1097 Deduplication on a Linked List (25 分)
题意:
输入一个地址和一个正整数N(<=100000),接着输入N行每行包括一个五位数的地址和一个结点的值以及下一个结点的地址。输出除去具有相同绝对值的结点的链表以及被除去的链表(由被除去的结点组成的链表)。
AAAAAccepted code:
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int nex[],val[];
vector<pair<int,int> >ans,ans2;
int vis[];
int main(){
//ios::sync_with_stdio(false);
//cin.tie(NULL);
//cout.tie(NULL);
int s,n;
cin>>s>>n;
for(int i=;i<=n;++i){
int x,y,z;
cin>>x>>y>>z;
nex[x]=z;
val[x]=y;
}
while(s!=-){
if(vis[abs(val[s])]){
ans2.push_back({s,val[s]});
s=nex[s];
continue;
}
ans.push_back({s,val[s]});
vis[abs(val[s])]=;
s=nex[s];
}
for(int i=;i<ans.size();++i){
printf("%05d %d ",ans[i].first,ans[i].second);
if(i<ans.size()-)
printf("%05d\n",ans[i+].first);
else
printf("-1\n");
}
for(int i=;i<ans2.size();++i){
printf("%05d %d ",ans2[i].first,ans2[i].second);
if(i<ans2.size()-)
printf("%05d\n",ans2[i+].first);
else
printf("-1\n");
}
return ;
}
【PAT甲级】1097 Deduplication on a Linked List (25 分)的更多相关文章
- PAT甲级——1097 Deduplication on a Linked List (链表)
本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91157982 1097 Deduplication on a L ...
- PAT Advanced 1097 Deduplication on a Linked List (25) [链表]
题目 Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplica ...
- PAT甲级:1066 Root of AVL Tree (25分)
PAT甲级:1066 Root of AVL Tree (25分) 题干 An AVL tree is a self-balancing binary search tree. In an AVL t ...
- PAT (Advanced Level) Practise - 1097. Deduplication on a Linked List (25)
http://www.patest.cn/contests/pat-a-practise/1097 Given a singly linked list L with integer keys, yo ...
- PAT甲级题解-1097. Deduplication on a Linked List (25)-链表的删除操作
给定一个链表,你需要删除那些绝对值相同的节点,对于每个绝对值K,仅保留第一个出现的节点.删除的节点会保留在另一条链表上.简单来说就是去重,去掉绝对值相同的那些.先输出删除后的链表,再输出删除了的链表. ...
- PAT甲级——A1097 Deduplication on a Linked List
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated ...
- PAT (Advanced Level) 1097. Deduplication on a Linked List (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- 1097. Deduplication on a Linked List (25)
Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated ...
- PAT 甲级 1002 A+B for Polynomials (25 分)
1002 A+B for Polynomials (25 分) This time, you are supposed to find A+B where A and B are two polyno ...
随机推荐
- 用html5自带表单验证 并且用ajax提交的解决方法(附例子)
用submit来提交表单,然后在js中监听submit方法,用ajax提交表单最后阻止submit的自动提交. 在标准浏览器中,阻止浏览器默认行为使用event.preventDefault(),而在 ...
- HTTP状态码的浪漫故事
小明是一个程序员,经常加班,在一个和尚部门,一个妹子都没有,所以一直单身. 404(Not Found):服务器无法根据客户端的请求找到资源(网页) 过年回家,老爸老妈给门开一条缝,先看看小明身后-- ...
- dp--B - Hard problem
B - Hard problem Vasiliy is fond of solving different tasks. Today he found one he wasn't able to so ...
- Python + Selenium +Chrome 批量下载网页代码修改【新手必学】
Python + Selenium +Chrome 批量下载网页代码修改主要修改以下代码可以调用 本地的 user-agent.txt 和 cookie.txt来达到在登陆状态下 批量打开并下载网页, ...
- Adobe 系列下载链接
(注意!:在下方链接前加上 "pan.baidu.com/s/" 才是正确网址,用"百度网盘"下载) Photoshop 专区(图像处理软件) Adobe Ph ...
- 拓扑排序 判断给定图是否存在合法拓扑序列 自家oj1393
//拓扑排序判断是否有环 #include<cstdio> #include<algorithm> #include<string.h> #include<m ...
- python基础数据类型 数据类型
数据类型 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值.但是,计算机能处理的远不止数值,还可以处理文本.图形.音频.视频.网页等各种各样的数据,不同的数据,需要定 ...
- «»<>
空格 «双小于 »双大于 <小于 >大于
- 关于Dev-C++的安装以及基本使用方法
我觉得Dev-C++是一款小巧方便的编译器,就给那些刚刚学习编程的同学讲一下这个软件的安装和基本的编译以及一些使用的技巧. (完全是傻瓜式的截图和教程,内容过于冗余,主要是考虑到这些新生没有接触过编程 ...
- Tomcat配置过程
Tomcat的配置其实还是挺简单的,下面是在Myeclipse中配置 1.首先要在Tomcat官网下载,网址:http://tomcat.apache.org/,然后左侧会有Download,选择你要 ...