题意:

输入一个地址和一个正整数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 分)的更多相关文章

  1. PAT甲级——1097 Deduplication on a Linked List (链表)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91157982 1097 Deduplication on a L ...

  2. 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 ...

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

  4. 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 ...

  5. PAT甲级题解-1097. Deduplication on a Linked List (25)-链表的删除操作

    给定一个链表,你需要删除那些绝对值相同的节点,对于每个绝对值K,仅保留第一个出现的节点.删除的节点会保留在另一条链表上.简单来说就是去重,去掉绝对值相同的那些.先输出删除后的链表,再输出删除了的链表. ...

  6. 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 ...

  7. PAT (Advanced Level) 1097. Deduplication on a Linked List (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. Git 时光穿梭机

    git log 提交日志 git reflog 命令日志 git status 查看状态 管理修改 git diff 工作区与暂存区 git diff master 工作区与版本库 git diff ...

  2. WPF页面切换

    XAML <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft. ...

  3. 阻止click点击事件

    遇到一个屏蔽点击事件,以前一般都是通过js控制,阻止事件,今天看到css加一个样式就能屏蔽,来记录一下 //css禁用鼠标点击事件 .test { pointer-events: none; } 随便 ...

  4. 如何删除github中的repository

    打开个人界面->点击进入想删除的repository的界面->拉到最下面的danger zone->delete

  5. $ ssh -T -v git@github.com_在本地用ssh连接github出错_git@github.com: Permission denied (publickey).

    $ ssh -T -v git@github.com报错: debug1: Authentications that can continue: publickey debug1: Next auth ...

  6. centos源码安装git最新版

    到 git官网下载git 源码安装包,git官网地址:https://www.git-scm.com/ 选择Tarballs系列的安装包,官网git下载:https://mirrors.edge.ke ...

  7. YAML(YML)语法详解

    ansible playbook是由yaml(yml)语法书写,结构清晰,可读性强,所以必须掌握yaml(yml)基础语法 语法 描述 锁进  YAML使用固定的缩进风格表示层级结构,每个缩进由两个空 ...

  8. idea中运行ssm 或springboot项目时,project Structure的配置

    ctrl+alt+shift+s进入 project Structure 首先是project选项 Modules 标明source testsource 以及 resource 和 testreso ...

  9. Python六剑客

    1.切片 切片:截取可迭代对象的部分内容(list,tuple,dict,set,str) 2.列表解析式 列表解析式可以快速的生成一个列表 不带if条件的: 格式:[expression for i ...

  10. sqli-libs(29(jspstudy)-31关)

    Less_29 Less-29: 需要用到jspstudy跟phpstudy   搭建jspstudy: sqli-labs-master文件夹下面还有tomcat文件,这才是真正的关卡,里面的jsp ...