当前位置:网站首页>Group programming ladder race - exercise set l2-002 linked list de duplication
Group programming ladder race - exercise set l2-002 linked list de duplication
2022-07-04 07:59:00 【Cod_ ing】
characteristic : use Hash surface
#include<iostream>
#include<unordered_map>
#include<map>
#include<string>
#include<vector>
using namespace std;
struct ListNode {
string addr;
string next;
int data;
};
int f_abs(int x) {
if (x > 0) return x;
return -x;
}
int main() {
unordered_map<string, ListNode> LinkList; //Hash surface , Store the original linked list
vector<ListNode> Deleted; // Store the deleted linked list nodes
map<int, int> nums; // Mark whether this number exists
string head;
int n;
cin >> head >> n;
string addr, next;
int data;
int cur = 0;
for (int i = 0; i < n; i++) {
cin >> addr >> data >> next;
LinkList[addr].addr = addr;
LinkList[addr].data = data;
LinkList[addr].next = next;
}
LinkList["-1"]; //address=-1 As the termination condition of iteration
string pre_node = head;
string node = LinkList[head].next;
nums[f_abs(LinkList[pre_node].data)] = 1; // First store the number of header nodes
while (node!= "-1") {
int x = f_abs(LinkList[node].data);
nums[x]++;
if (nums[x]>1) {
// This number has appeared before
if (cur > 0) {
// The previous node of the node in the deleted node linked list needs special treatment , Change next value
Deleted[cur - 1].next = node;
}
Deleted.push_back({
node, "-1", LinkList[node].data }); // Inserted nodes next The assignment is -1
cur++;
LinkList[pre_node].next = LinkList[node].next;
node = LinkList[node].next;
}
else {
pre_node = node;
node = LinkList[node].next;
}
}
//cout << endl;
node = head;
while (node != "-1") {
cout << node << " " << LinkList[node].data << " " << LinkList[node].next<<endl;
node = LinkList[node].next;
}
//cout << endl; Output delete node
for (ListNode x : Deleted) {
cout << x.addr << " " << x.data << " " << x.next << endl;
}
return 0;
}
边栏推荐
- Google's official response: we have not given up tensorflow and will develop side by side with Jax in the future
- L1-030 one gang one (15 points)
- R language ggplot2 visualization: ggplot2 visualization grouping box diagram, place the legend and title of the visualization image on the top left of the image and align them to the left, in which th
- 谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
- NPM run build error
- [go basics] 1 - go go
- Go h*ck yourself:online reconnaissance (online reconnaissance)
- The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
- 神经网络入门(下)
- SQL注入测试工具之Sqli-labs下载安装重置数据库报错解决办法之一(#0{main}thrown in D:\Software\phpstudy_pro\WWW\sqli-labs-……)
猜你喜欢
Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée
MySQL中的文本處理函數整理,收藏速查
深入浅出:了解时序数据库 InfluxDB
User login function: simple but difficult
[performance test] read JMeter
Node foundation ~ node operation
谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
Oracle-存储过程与函数
[test de performance] lire jmeter
[go basics] 2 - go basic sentences
随机推荐
深入浅出:了解时序数据库 InfluxDB
Moher college phpMyAdmin background file contains analysis traceability
Life planning (flag)
谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展
PCIE知识点-010:PCIE 热插拔资料从哪获取
Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée
猜数字游戏
真空介电常数和真空磁导率究竟是由什么决定的?为何会存在这两个物理量?
Devops Practice Guide - reading notes (long text alarm)
NPM run build error
Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)
University stage summary
Set and modify the page address bar icon favicon ico
1、卡尔曼滤波-最佳的线性滤波器
BUUCTF(4)
Need help resetting PHP counters - PHP
PCIe knowledge points -010: where to get PCIe hot plug data
团体程序设计天梯赛-练习集 L2-002 链表去重
zabbix監控系統自定義監控內容
MySQL 数据库 - 函数 约束 多表查询 事务