当前位置:网站首页>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;
}
边栏推荐
- MySQL 数据库 - 函数 约束 多表查询 事务
- [go basics] 2 - go basic sentences
- Used on windows Bat file startup project
- Moher College webmin unauthenticated remote code execution
- This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears
- Oracle-存储过程与函数
- 节点基础~节点操作
- JVM中堆概念
- ZABBIX 5.0 monitoring client
- 时序数据库 InfluxDB 2.2 初探
猜你喜欢
Preliminary study on temporal database incluxdb 2.2
【性能测试】一文读懂Jmeter
Common components of flask
Unity text superscript square representation +text judge whether the text is empty
[real case] how to deal with the failure of message consumption?
Detailed introduction to the big changes of Xcode 14
[gurobi] establishment of simple model
How to use MOS tube to realize the anti reverse connection circuit of power supply
Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée
Go learning notes - constants
随机推荐
Go learning notes - constants
1. Getting started with QT
MySQL中的文本處理函數整理,收藏速查
Thesis learning -- time series similarity query method based on extreme point characteristics
L1-022 odd even split (10 points)
Activiti common operation data table relationship
How to improve your system architecture?
21 examples of strategic goals to promote the rapid development of your company
Unity opens the explorer from the inspector interface, selects and records the file path
Take you to master the formatter of visual studio code
Moher college phpMyAdmin background file contains analysis traceability
Would you like to go? Go! Don't hesitate if you like it
Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
线性代数1.1
Node foundation ~ node operation
ZABBIX monitoring system deployment
How to set multiple selecteditems on a list box- c#
Need help resetting PHP counters - PHP
WordPress get_ Users() returns all users with comparison queries - PHP
Set and modify the page address bar icon favicon ico