1097. Deduplication on a Linked List (25)

时间限制
300 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Given a singly linked list L with integer keys, you are supposed to remove the nodes with duplicated absolute values of the keys. That is, for each value K, only the first node of which the value or absolute value of its key equals K will be kept. At the mean time, all the removed nodes must be kept in a separate list. For example, given L being 21→-15→-15→-7→15, you must output 21→-15→-7, and the removed list -15→15.

Input Specification:

Each input file contains one test case. For each case, the first line contains the address of the first node, and a positive N (<= 105) which is the total number of nodes. The address of a node is a 5-digit nonnegative integer, and NULL is represented by -1.

Then N lines follow, each describes a node in the format:

Address Key Next

where Address is the position of the node, Key is an integer of which absolute value is no more than 104, and Next is the position of the next node.

Output Specification:

For each case, output the resulting linked list first, then the removed list. Each node occupies a line, and is printed in the same format as in the input.

Sample Input:

00100 5
99999 -7 87654
23854 -15 00000
87654 15 -1
00000 -15 99999
00100 21 23854

Sample Output:

00100 21 23854
23854 -15 99999
99999 -7 -1
00000 -15 87654
87654 15 -1

提交代码

为了方便,要加头指针。

 #include<cstdio>
#include<stack>
#include<algorithm>
#include<iostream>
#include<stack>
#include<set>
#include<map>
using namespace std;
struct ndoe{
int k,next;
};
ndoe mem[];
bool ha[];
int abs(int a){
if(a<){
a=-a;
}
return a;
}
#define refirst 100001
#define nrfirst 100002
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,first;
scanf("%d %d",&first,&n);
int i,cur;
for(i=;i<n;i++){
scanf("%d",&cur);
scanf("%d %d",&mem[cur].k,&mem[cur].next);
}
cur=nrfirst;
int relist=refirst,p=first;
while(p!=-){
while(p!=-&&ha[abs(mem[p].k)]){
mem[relist].next=p;
relist=p;
p=mem[p].next;
}
if(p!=-){
ha[abs(mem[p].k)]=true;
}
mem[cur].next=p;
if(p!=-){
cur=p;
p=mem[cur].next;
}
}
mem[relist].next=-;
p=mem[nrfirst].next;
while(p!=-){
if(mem[p].next!=-){
printf("%05d %d %05d",p,mem[p].k,mem[p].next);
}
else{
printf("%05d %d %d",p,mem[p].k,mem[p].next);
}
printf("\n");
p=mem[p].next;
}
p=mem[refirst].next;
while(p!=-){
if(mem[p].next!=-){
printf("%05d %d %05d",p,mem[p].k,mem[p].next);
}
else{
printf("%05d %d %d",p,mem[p].k,mem[p].next);
}
printf("\n");
p=mem[p].next;
}
return ;
}

pat1097. Deduplication on a Linked List (25)的更多相关文章

  1. PAT1097:Deduplication on a Linked List

    1097. Deduplication on a Linked List (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 ...

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

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

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

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

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

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

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

  7. 【PAT甲级】1097 Deduplication on a Linked List (25 分)

    题意: 输入一个地址和一个正整数N(<=100000),接着输入N行每行包括一个五位数的地址和一个结点的值以及下一个结点的地址.输出除去具有相同绝对值的结点的链表以及被除去的链表(由被除去的结点 ...

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

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

  9. PAT_A1097#Deduplication on a Linked List

    Source: PAT A1097 Deduplication on a Linked List (25 分) Description: Given a singly linked list L wi ...

随机推荐

  1. 解决启动SQL Server Management Studio 17时报Cannot find one of more components...的问题

    刚装好SSMS 17.1准备体验,弹出: 一番搜索,普遍办法都是安装VS2015独立shell.删除某个注册表项什么的,没用,首先这个shell我是装了的,然后也没有那个注册表项.我自己尝试过重装sh ...

  2. inner join ,left join ,right join区别

    inner join ,left join ,right join区别 left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 right join(右联接) 返回包括右表中 ...

  3. <正则吃饺子>:关于java中垃圾回收技术的简单学习总结

    知识介绍来自网络,后面会根据继续学习进行补充和适当的修改,谢谢!原文地址:http://www.importnew.com/26821.html#comment-578355 java中的垃圾回收机制 ...

  4. jprofiler9.1.1 安装与配置

    一.安装部分 安装包: 1.jprofiler_linux_9_1_1.rpm 2.jprofiler_windows-x64_9_1_1.exe 需要注意的是,Linux 和 Windows 安装的 ...

  5. RStudio 断点调试 进入for循环语句调试

    参考: http://www.rstudio.com/ide/docs/debugging/overview 1.进入调试模式 全选代码,点击source即可进入调试模式. 2.进入for 调试 在F ...

  6. Jenkins配置有用摘抄笔记

    使用jenkins配置.net mvc5网站自动构建全过程记录  转自:http://www.cnblogs.com/baiyunchen/p/4724350.html 持续集成是个简单重复劳动,人来 ...

  7. Hashtable类中的四种遍历方法对比

    要遍历一个Hashtable,api中提供了如下几个方法可供我们遍历: keys() - returns an Enumeration of the keys of this Hashtable ke ...

  8. 【Android-stdio-appdemo搭建记录】

    1-如何删除存在的工程 2-创建Android项目 next设置app兼容最低版本:api15--android 4.0以上 创建活动页面 设置活动页面的名称 创建成功项目以后会有最基本的layout ...

  9. [CentOS7] vncviewer与windows之间的复制粘贴

    转载:https://my.oschina.net/seava/blog/226966 用VNC连接到Linux之后,最纠结的问题就是无法复制粘贴.其实很简单,在Linux里面,打开一个终端,然后输入 ...

  10. Java实例练习——java实现自动生成长度为10以内的随机字符串(可用于生成随机密码)

    package sorttest; import java.util.ArrayList; import java.util.Collections; import java.util.List; i ...