当前位置:网站首页>TIANTI race - l2-002 linked list weight removal (25 points)
TIANTI race - l2-002 linked list weight removal (25 points)
2022-04-22 14:22:00 【wowon~】
L2-002 The chain watch is weightless (25 branch )
Given a linked list with integer keys L, You need to delete the key node where the absolute value is repeated . For each key value K, Only the first absolute value is equal to K The nodes of are reserved . meanwhile , All deleted nodes must be saved in another linked list . For example, given L by 21→-15→-15→-7→15, You need to output the list after de duplication 21→-15→-7, And the deleted list -15→15.
Input format :
Enter... On the first line L The address of the first node and a positive integer N(≤105, Is the total number of nodes ). The address of a node is nonnegative 5 An integer , Empty address NULL use −1 To express .
And then N That's ok , Each line describes a node in the following format :
Address Key value Next node
among Address Is the address of the node , Key value It's absolutely no more than 104 The integer of , Next node Is the address of the next node .
Output format :
First output the list after de duplication , Then output the deleted list . Each node occupies a row , Output... In input format .
sample input :
00100 5
99999 -7 87654
23854 -15 00000
87654 15 -1
00000 -15 99999
00100 21 23854
sample output :
00100 21 23854
23854 -15 99999
99999 -7 -1
00000 -15 87654
87654 15 -1
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=10100;
struct node// Store three values for each row
{
string idx;
int e;
string ne;
};
map<string,node>mp;// Actually store each row , Subscript is address
int book[100010];// Subscript to be i The absolute value of appears several times
int main()
{
string s;
int n;
cin>>s>>n;
for(int i=0;i<n;i++)
{
string a,c;
int b;
cin>>a>>b>>c;
mp[a]={a,b,c};
}
vector<node>ans1,ans2;// Store the deleted linked list and the deleted linked list respectively
// cout<<n<<endl;
// ans1[0].idx=s;
for(int i=1;i<=n;i++)// Deal with this n Data
{
// cout<<",,,,"<<endl;
node t=mp[s];
if(book[abs(t.e)]>=1)// There have been Just store it in ans2 Inside
{
if(ans2.size()>=1)
{
ans2[ans2.size()-1].ne=t.idx;
}
ans2.push_back(t);
}
else// There has been no ans1 Middle and processed pointer
{
book[abs(t.e)]++;
if(ans1.size()>=1)
{
ans1[ans1.size()-1].ne=t.idx;
}
ans1.push_back(t);
}
if(t.ne=="-1")break;
s=t.ne;
}
ans1[ans1.size() - 1].ne = "-1";
if (ans2.size() != 0)
ans2[ans2.size() - 1].ne = "-1";
for(auto i:ans1)
cout<<i.idx<<" "<<i.e<<" "<<i.ne<<endl;
for(auto i:ans2)
cout<<i.idx<<" "<<i.e<<" "<<i.ne<<endl;
return 0;
}
版权声明
本文为[wowon~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221416432991.html
边栏推荐
- POM in idea Mysql5. XML file 7 coordinate red error
- HashTable哈希表与统计594、350、|554、609、454、18
- Development and application of deep learning technology
- 深入剖析volatile原理
- Cloudera Manager HA模式搭建
- 10天完成民猫电商毕设——用户模块实现(2nd day)
- Ibeacon development summary of Internet of things solution based on tailing micro tlsr825x
- 獲取數據庫中數值時,數據庫有值,卻為空??
- 20道25K+Android工程师面试必问面试题,网易Android面试必问
- 深入剖析阻塞队列BlockingQueue (详解ArrayBlockingQueue和LinkedBlockingQueue及其应用)
猜你喜欢
26岁,0基础学软件测试还来得及吗

Linked list ring linked list linked list ring judgment to find the ring in nodes 141 and 142

2. Flddler response shows the solution to the problem of garbled code

How to get tuphub Today's hot list and heat?

Bitmap bloomfilter BitSet details

With Feixiang, this task management artifact, the work is more convenient and efficient

二月份,我靠这一份PDF文档面试BAT,没想到竟然收到了5个offer

Timer--

LeetCode_63 不同路径 II

Thread pool--
随机推荐
2. Flddler response shows the solution to the problem of garbled code
双指针||有序数组去重 排序链表移除元素 26、27、83
Blocking queue-
Full solution of database SQL
Redis connection tool cannot connect to redis in docker
Codeforces Round #782 (Div. 2) D. Reverse Sort Sum
Getting started with shell
An error is reported when reading the attribute value of the object through the variable storage key value in TS (TS: 7053)
Binarytree练习二叉树层序遍历 || 用队列实现层序遍历
Redis 批量删除数据(通配符)
Daily question - Three Kingdoms game (diagonal matrix)
深入剖析volatile原理
Redis batch delete data (wildcard)
Timer--
2020 popular whole network series: This is a very suitable Android advanced - interview key and difficult data notes for collection and collection! Continuously update the high-quality interview links
TensorFlow-ValueError: ‘images‘ contains no shape
图 钥匙和房间
CorelDRAW插件-CPG插件开发-环境搭建-VS2017-TLB文件-CDR插件
20道25K+Android工程师面试必问面试题,网易Android面试必问
Mariadb互为主从(双主模式)配置