题意:

输入一个地址和一个正整数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. C# 获取变量的指针(IntPtr)

     1. 获取数组的指针(IntPtr) 通过Marshal.UnsafeAddrOfPinnedArrayElement(Array,Int32)方法获得一个数组的第某个元素的内存地址. Array是 ...

  2. 剑指offer 面试题. 二叉搜索树的第k个结点

    题目描述 给定一棵二叉搜索树,请找出其中的第k小的结点.例如, (5,3,7,2,4,6,8)    中,按结点数值大小顺序第三小结点的值为4.     解: 由于二叉搜索树的中序遍历是升序,所以在中 ...

  3. 为什么html表单用post提交后,提交页面是空白

    为什么html表单用post提交后,提交页面是空白? 因为post提交就应该用doPost()方法处理数据

  4. Go_sqlx和占位符

    sqlx使用 第三方库sqlx能够简化操作,提高开发效率. 安装 go get github.com/jmoiron/sqlx package main import ( "fmt" ...

  5. 不间断会话服务:screen

    1.screen命令: screen 是一款能够实现多窗口远程控制的开源服务程序,简单来说就是为了解决网络异 常中断或为了同时控制多个远程终端窗口而设计的程序.用户还可以使用 screen 服务程序同 ...

  6. linux deploy---旧手机变废为宝

    前几天朋友送了我一部红米Note 1s,本来不想要,转念一想,不要白不要,就收了. 拿到之后我就想,这么一个1+8的手机能做什么呢? 翻遍了CSDN和简书,找到了一个性价比不错的方法:给旧手机装上一个 ...

  7. 励志成为优产的母猪--------猜数游戏 ,历史记录,pickle保存,队列deque

    # pickle 可以处理复杂的序列化语法.(例如自定义的类的方法,游戏的存档等),存档以文件的形式保存 参见 https://www.cnblogs.com/abobo/p/8080447.html ...

  8. 265. 粉刷房子 II

    Q: A: 首先这题可以和粉刷房子这题一样解法,对于i号房子,遍历k种颜色,对于每一种,都去找i-1号房子除该颜色之外的最小花费.但上一题是3种颜色,总复杂度O(N),这题k种颜色,复杂度O(NK^2 ...

  9. android关闭屏幕时不锁屏实现

    所需权限: <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/> 关闭系统锁屏服务 ...

  10. jquery实现点击显示,再点击隐藏

    //点击a标签,轮流显示和隐藏<div id="timo" style="background-color:red;height:50px;width:50px;& ...