当前位置:网站首页>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;
}
边栏推荐
- OKR vs. KPI 一次搞清楚这两大概念!
- How to write a summary of the work to promote the implementation of OKR?
- L1-027 rental (20 points)
- 弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东
- 1. Getting started with QT
- Wechat has new functions, and the test is started again
- Put a lantern on the website during the Lantern Festival
- Add log file to slim frame - PHP
- Would you like to go? Go! Don't hesitate if you like it
- 节点基础~节点操作
猜你喜欢

Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée

L1-027 rental (20 points)

Go learning notes - constants

Easy to understand: understand the time series database incluxdb

Take you to master the formatter of visual studio code

SQL注入测试工具之Sqli-labs下载安装重置数据库报错解决办法之一(#0{main}thrown in D:\Software\phpstudy_pro\WWW\sqli-labs-……)

Oracle stored procedures and functions
![[test de performance] lire jmeter](/img/c9/25a0df681c7ecb4a0a737259c882b3.png)
[test de performance] lire jmeter

弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东

In the era of low code development, is it still needed?
随机推荐
Activiti常见操作数据表关系
How to use MOS tube to realize the anti reverse connection circuit of power supply
How does dataframe calculate the average value of each row as another column
PCIE知识点-010:PCIE 热插拔资料从哪获取
Unity write word
L1-030 one gang one (15 points)
Handwritten easy version flexible JS and source code analysis
zabbix 5.0监控客户端
Application of isnull in database query
Common components of flask
Ecole bio rushes to the scientific innovation board: the annual revenue is 330million. Honghui fund and Temasek are shareholders
Unity text superscript square representation +text judge whether the text is empty
Text processing function sorting in mysql, quick search of collection
R language uses cforest function in Party package to build random forest based on conditional inference trees, uses varimp function to check feature importance, and uses table function to calculate co
L1-023 output gplt (20 points)
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)
神经网络入门(下)
L1-028 judging prime number (10 points)
L1-025 positive integer a+b (15 points)
Linear algebra 1.1