【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 ...
随机推荐
- C# ODP.Net oracle数据库操作 支持不安装客户端
下载: http://download.oracle.com/otn/other/ole-oo4o/ODTwithODAC1110720.zip?AuthParam=1414811820_e61f2f ...
- python3练习100题——013
熟悉的水仙花数来了,,,... 原题链接:http://www.runoob.com/python/python-exercise-example13.html 题目:打印出所有的"水仙花数 ...
- LitElement(五)事件
1.概述 1.1 在何处添加事件监听器 您需要以一种可以在事件发生之前触发的方法添加事件监听器.但是,为了获得最佳的加载性能,应尽可能晚添加事件监听器. 你可以在以下位置添加事件监听器: 1.1.1 ...
- 未能加载文件或程序集“Autofac.Integration.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
是因为web.config中dependentAssembly结点下的版本号和当前引用的程序集的版本号不一致!
- 配置本地https
参考 https://juejin.im/post/5a6db896518825732d7fd8e0 https://juejin.im/post/590ec765a22b9d0058fcfaa5 比 ...
- JQuery/JS插件 jsTree加载树,普通加载,点一级加载一级
前端: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <tit ...
- OPGL+VS2017+GLFW+GLEW配置详细步骤
OPGL+VS2017+GLFW+GLEW配置详细步骤: https://blog.csdn.net/weixin_40921421/article/details/80211813 原博客地址:ht ...
- JavaWeb项目中的Servlet
1.创建Servlet 2.在jsp中用ajax调用 $.post("<%=request.getContextPath()%>/AjaxValidationServlet&qu ...
- 【C语言】输入一个字符串,并对字符串中的偶数位置的字符按从小到大的顺序排序,奇数位置的字符不动,输出排序后的结果
#include <stdio.h> #include<string.h> int main() { ]; int i,j,k,len; gets_s(a); len= str ...
- android .9背景图作为TextView背景时文字无法居中问题
问题产生原因: .9图黑色边框绘制伸缩区域有问题,重叠的最大区域是TextView文字所能显示的区域 如下图所示,横向和纵向最大重叠部分就是文字可显示部分,这个图作为背景后文字整体偏下,无法上下居中对 ...