PAT-GPLT训练集 L2-002 链表去重

题目大意为给出一个单链表,去除重复的结点,输出删除后的链表,并且把被删除的结点也以链表形式输出

思路:把这个链表直接分成两个链表,再直接输出就可以

代码:

#include<iostream>
#include<cstdio>
#include<set>
#include<cmath>
using namespace std;
const int MAX_N = +;
typedef struct { int address, key, next; } P;
P a[MAX_N], b[MAX_N], c[MAX_N]; set<int> check;
int n, s;
int main() {
cin >> s >> n;
int from, key, to;
for(int i = ; i < n; i++) {
scanf("%d%d%d", &from, &key, &to);
a[from].address = from;
a[from].key = key;
a[from].next = to;
}
int c1 = , c2 = ;
while(s != -) {
if(check.count(abs(a[s].key))) {
c[c2++] = a[s];
} else {
check.insert(abs(a[s].key));
b[c1++] = a[s];
}
s = a[s].next;
}
for(int i = ; i < c1; i++) {
if(!i) printf("%05d %d ", b[i].address, b[i].key);
else printf("%05d\n%05d %d ", b[i].address, b[i].address, b[i].key);
}
printf("-1\n");
for(int i = ; i < c2; i++) {
if(!i) printf("%05d %d ", c[i].address, c[i].key);
else printf("%05d\n%05d %d ", c[i].address, c[i].address, c[i].key);
}
if(c2) printf("-1");
return ;
}

PAT-GPLT训练集 L2-002 链表去重的更多相关文章

  1. PAT乙级真题及训练题 1025. 反转链表 (25)

    PAT乙级真题及训练题 1025. 反转链表 (25) 感觉几个世纪没打代码了,真是坏习惯,调了两小时把反转链表调出来了,心情舒畅. 这道题的步骤 数据输入,数组纪录下一结点及储存值 创建链表并储存上 ...

  2. PTA L2-002 链表去重 团体程序设计天梯赛-练习集

    L2-002 链表去重(25 分)   给定一个带整数键值的链表 L,你需要把其中绝对值重复的键值结点删掉.即对每个键值 K,只有第一个绝对值等于 K 的结点被保留.同时,所有被删除的结点须被保存在另 ...

  3. PAT 天梯赛练习集 L2-022. 重排链表

    题目链接:https://www.patest.cn/contests/gplt/L2-022 给定一个单链表 L1→L2→...→Ln-1→Ln,请编写程序将链表重新排列为 Ln→L1→Ln-1→L ...

  4. 团体程序设计天梯赛-练习集L2-002. 链表去重

    L2-002. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除 ...

  5. pat 团体天梯赛 L2-002. 链表去重

    L2-002. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 给定一个带整数键值的单链表L,本题要求你编写程序,删除 ...

  6. 天梯 L2 链表去重

    L2-002 链表去重 (25 分) 给定一个带整数键值的链表 L,你需要把其中绝对值重复的键值结点删掉.即对每个键值 K,只有第一个绝对值等于 K 的结点被保留.同时,所有被删除的结点须被保存在另一 ...

  7. L2-002. 链表去重

    L2-002. 链表去重 题目链接:https://www.patest.cn/contests/gplt/L2-002 这题因为结点地址只有四位数,所以可以直接开一个10000的数组模拟内存就好了. ...

  8. 机器学习在入侵检测方面的应用 - 基于ADFA-LD训练集训练入侵检测判别模型

    1. ADFA-LD数据集简介 ADFA-LD数据集是澳大利亚国防学院对外发布的一套主机级入侵检测数据集合,包括Linux和Windows,是一个包含了入侵事件的系统调用syscall序列的数据集(以 ...

  9. L2-002. 链表去重---模拟

    https://www.patest.cn/contests/gplt/L2-002 L2-002. 链表去重 时间限制 300 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 ...

随机推荐

  1. swfupload上传图片

    项目结构 以及插件需要的文件如图所示 前端代码: <!DOCTYPE html> <html> <head> <title>SWFUpload</ ...

  2. iterrows(), iteritems(), itertuples()对dataframe进行遍历

      iterrows(): 将DataFrame迭代为(insex, Series)对. itertuples(): 将DataFrame迭代为元祖. iteritems(): 将DataFrame迭 ...

  3. ZZNUOJ 2022 摩斯密码

    map打表存一下对应的密码   不会map感觉不好弄这题 #include<stdio.h> #include<string.h> #include<math.h> ...

  4. ashx和aspx的区别

    1. ashx是一般处理程序,一般返回的数据有两种,一种是html页面,一种是只返回一个字符串. 2. aspx是web窗体程序,每次新建都回自带一个界面和一个后台处理程序. 3. 根据以上两点,可以 ...

  5. Study之6 Neutron(配置使用 Routing)-devstack

    ●Neutron 的路由服务是由 l3 agent 提供的. 除此之外,l3 agent 通过 iptables 提供 firewall 和 floating ip 服务. l3 agent 需要正确 ...

  6. angular2 学习笔记 (Typescript - Attribute & reflection & decorator)

    更新 : 2018-11-27 { date: Date } 之前好像搞错了,这个是可以用 design:type 拿到的 { date: Date | null } 任何类型一但配上了 | 就 de ...

  7. composer修改中文镜像

    composer config -g repo.packagist composer https://packagist.phpcomposer.com

  8. array_map的使用

    其结果为:

  9. 协方差分析 | ANCOVA (Analysis of Covariance)

    If you are worried about leaving out covariates you could regress out them first and analyse the res ...

  10. OnSen UI结合AngularJs打造”美团"APP"逛一逛”页面 --Hybrid App

    1.页面效果图: 演示链接地址:http://www.nxl123.cn/bokeyuan/meiTuanDemo_walk/ 2.核心代码 walk.html: <ons-page id=&q ...