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. Design:目录

    ylbtech-Design:目录 1.返回顶部 1. http://idesign.qq.com/#!index/feed 2. https://www.behance.net/ 3. 2.返回顶部 ...

  2. libvirt, libvirt-python, libvirtd 关系浅析

    libvirt 官方解释:  http://libvirt.org/ 见分隔线以下. 我的理解:libvirt 作为一个中间层,封装了对下层虚拟化 hypervisor 的操作方法.也就是说,无论你是 ...

  3. ES6学习之Generator函数

    概念:可以把Generator 函数理解成状态机(封装了多个内部状态)或者是一个遍历器对象生成函数 写法:Generator函数的定义跟普通函数差不多,只是在function关键字后面加了一个星号 f ...

  4. C语言学习笔记--struct 和 union关键字

    1.struct关键字 C 语言中的 struct 可以看作变量的集合struct中的每个数据成员都有独立的存储空间. 结构体与柔性数组 (1)柔性数组即数组大小待定的数组 (2)C 语言中可以由结构 ...

  5. ObjectInputStream缓存数据

    DataManager /** * 本地数据的存储 * @author Administrator * */ public class DataManager { private static fin ...

  6. Angular08 依赖注入

    1 angular应用中依赖注入的工作原理 技巧01:在模块级别进行注册时所有在应用级别的组件都可以使用,因为主模块会导入其他模块,所以在模块中注入就相当于在主模块进行注入操作:懒加载的模块除外 技巧 ...

  7. Learning Python 008 正则表达式-002 findall()方法

    Python 正则表达式 - findall()方法 重点 findall()方法的使用 - 程序讲解 简单的符号的使用 正则表达式的库文件是re,先导入库文件: import re .的使用举例 # ...

  8. Code Page Identifiers - Copy from Microsoft

    Code Page Identifiers 78 out of 94 rated this helpful - Rate this topic   The following table define ...

  9. Eclipse超级有用的快捷键

    1.Alt + Shift + R 重构 2.Ctrl + F11 运行并调试程序 3.Ctrl + Shift + O 自动导入包 4.Ctrl + Shift + F 格式化代码 5.F5 调试模 ...

  10. jQuery 选择表格(table)里的行和列及改变简单样式

    本文只是介绍如何用jQuery语句对表格中行和列进行选择以及一些简单样式改变,希望它可以对jQuery表格处理的深层学习提供一些帮助jQuery对表格(table)的处理提供了相当强大的功能,比如说对 ...