【PAT甲级题解】1097 Deduplication on a Linked List (25分)
Deduplication意为重复数据消除,Deplicated意为复制,是deduplication的过去式,题干大意为给定一个单链表L要求你对每一个结点的值判断,如果这个值的绝对值是第一次出现,那么将它们放在一起,如果这个结点的绝对值已经出现过了,那么按照出现顺序将他们单独存放,最后按照链表的形式输出,先输出第一次出现的主表,然后在输出重复的链表,这里题目有一个坑点,就是有一种3分的情况是没有重复的值得链表,这样的话需要判断再输出,具体方法PAT已经出过好多这种类似的题目了,无非就是对节点地址去重然后根据要求判断最后控制双重key标记的语句输出即可
代码:
#include<iostream>
#include<stdio.h>
#include<vector>
#include<unordered_map>
using namespace std;
const int maxn = 1e5+10;
struct node{int data;int next;
}list[maxn];
int main() {int first, n;cin >> first >> n;while (n--) {int temp;cin >> temp;cin >> list[temp].data >> list[temp].next;}vector<int> vt;while (first != -1) {vt.push_back(first);first = list[first].next;}unordered_map<int, int> mp;vector<int> ans[2];for (auto it : vt) {if (mp[abs(list[it].data)] == 0) {ans[0].push_back(it);mp[abs(list[it].data)] = 1;} else {ans[1].push_back(it);}}int key = 0;for (auto it : ans[0]) {if (!key) {printf("%05d %d ", it, list[it].data);key = 1;} else {printf("%05d\n%05d %d ", it, it, list[it].data);}}cout << -1 << endl;key = 0;for (auto it : ans[1]) {if (!key) {printf("%05d %d ", it, list[it].data);key = 1;} else {printf("%05d\n%05d %d ", it, it, list[it].data);}}if (key)cout << -1 << endl;return 0;
}
【PAT甲级题解】1097 Deduplication on a Linked List (25分)相关推荐
- 1097 Deduplication on a Linked List (25 分)_35行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given a singly linked list L with integer keys, you are supposed ...
- 【PAT甲级 链表去重】1097 Deduplication on a Linked List (25 分) C++ 全部AC
题目 思路: 先把题目中的链表读进内存 创建两个新链表listA, listB 遍历原链表,把重复的放进listB,不重复的放进listA.放的时候,注意处理一下后继next中存的值. 分别打印两个分 ...
- PTA甲级 1097 Deduplication on a Linked List (25分)-链表处理
文章目录 题目原文 Input Specification: Output Specification: Sample Input: Sample Output: 生词如下: 题目大意: 思路如下: ...
- 【PAT甲级题解记录】1148 Werewolf - Simple Version (20 分)
[PAT甲级题解记录]1148 Werewolf - Simple Version (20 分) 前言 Problem:1148 Werewolf - Simple Version (20 分) Ta ...
- 【PAT甲级 多项式相乘】1009 Product of Polynomials (25 分) C++ 全部AC
题目 思路 维护三个数组: arrA[1001]存储第一行数据 arrB[1001]存储第二行数据 c[1000000]存储计算结果 数组下标表示多项式的指数,数组存的内容表示多项式的系数 将arrA ...
- 【PAT - 甲级1006】Sign In and Sign Out (25分)(STLmap)
题干: At the beginning of every day, the first person who signs in the computer room will unlock the d ...
- 2019年9月8日秋季PAT甲级题解A1163(7-4)Dijkstra Sequence
2019年9月8日秋季PAT甲级题解 A1163(7-4)Dijkstra Sequence (30 分) #include<iostream> #include<vector> ...
- PAT甲级1097 Deduplication on a Linked List:[C++题解]遍历链表、两个vector
文章目录 题目分析 题目链接 题目分析 题意:删掉链表中数值绝对值相同的结点,将其放入另一个链表中.最后输出去重后的链表和删掉元素构成的链表. 分析:采用数组模拟链表,把链表存下来.然后遍历链表,该元 ...
- PAT甲级1123 Is It a Complete AVL Tree (30分):[C++题解]建立平衡树、bfs,判完全二叉树
文章目录 题目分析 题目链接 题目分析 来源:pat网站 本题作为进阶题,它的基础知识点如下几题. PAT甲级1066 Root of AVL Tree (25分):[C++题解]建立平衡树(AVL树 ...
最新文章
- python自动输出_python自动化报告的输出
- 手把手教你用Python模拟登录淘宝
- msbuild 语法_用于删除文件的MSBuild Task语法
- bash、dash(/bin/bash和/bin/sh)
- 聚类之K-means均值聚类
- 大型DCI网络智能运营实践
- NuGet社区使用体验调查
- STM32F429i-DISCO FreeRTOS keil STM32CubeMX
- mysql安装包说明
- OSChina 周四乱弹 —— 帅帅帅,飞一般的感觉~
- 怎么将抖音上的多个视频合成一个视频
- c# 从MySQL往sharpmap中加载矢量数据图层(一)
- linux vi 替换
- 探讨一种新型的双进程守护应用保活
- 初中计算机考试wps文字,初中信息技术WPS表格测试题.docx
- C#使用OleDB操作ACCESS插入数据时提示:参数 @p_Contract 没有默认值
- 电脑打开网页提示服务器错误是怎么回事,电脑打开网页 http500服务器错误 怎么办?...
- difflib模块_Python一起来找茬—difflib模块
- 淘米网汪海兵:为爱创业 刚进腾讯很失落(转载)
- 小程序分类功能的实现
热门文章
- 工程经济(专科)【2】
- 手写Spring-第四章-为依赖的对象注入灵魂!
- linux哪些程序需要指定终端,Linux程序员福利 - 追女友神奇(Linux终端运行炫酷程序)...
- 2022-2028全球与中国商业和工业微电网市场现状及未来发展趋势
- R语言raster包计算多个栅格图像平均值、标准差的方法
- grumble.js-非常酷的气泡提示插件
- RFID超高频标签阅读器分类
- html字体阴影怎么设置6,css怎么设置字体阴影,
- 基于laravel+workerman+easywechat的公众号客服系统
- Python入门习题大全——尝试登录次数