• A1097 Deduplication on a Linked List [链表去重]


    在这里插入图片描述

    #include<vector>
    #include<iostream>
    #include<algorithm>
    #include<unordered_map>
    #include<set>
    #include<map>
    #include<cstring>
    #include<string>
    #include<queue>
    #include<array>
    #include<stack>
    using namespace std;
    const int maxn = 100010;
    const int TABLE = 10001;
    struct Node
    {
    	int address,data,next;
    	bool flag;
    	int order;
    }node[maxn];
    bool cmp(Node a, Node b)
    {
    	return a.order < b.order;
    }
    bool isExist[TABLE];
    int main()
    {
    	memset(isExist, false, sizeof(isExist));
    	for (int i = 0; i < maxn; i++)
    	{
    		node[i].order = 2 * maxn;
    	}
    	int n, begin, address;
    	cin >> begin >> n;
    	for (int i = 0; i < n; i++)
    	{
    		cin >> address;
    		cin >> node[address].data >> node[address].next;
    		node[address].address = address;
    	}
    	int countvalid = 0, countRemoved = 0, p = begin;
    	while (p != -1)
    	{
    		if (!isExist[abs(node[p].data)]) {
    			isExist[abs(node[p].data)] = true;
    			node[p].order = countvalid++;
    		}
    		else
    		{
    			node[p].order = maxn + countRemoved++;
    		}
    		p = node[p].next;
    	}
    	sort(node, node + maxn, cmp);
    	int count = countvalid + countRemoved;
    	for (int i = 0; i < count; i++)
    	{
    		if (i != countvalid - 1 && i != count - 1)
    		{
    			printf("%05d %d %05d
    ", node[i].address, node[i].data,node[i+1].address);
    		}
    		else
    		{
    			printf("%05d %d -1
    ", node[i].address, node[i].data);
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    打开LogCat以便查看日志
    sql语句优化
    IIS部署说明
    VM上Hadoop3.1伪分布式模式搭建
    C# 程序结构
    CSS笔记1:属性定位
    VS2013 添加控制台程序
    布局 Layout
    [游泳] 游泳学习课程
    "12306"台前幕后:五年利益之争 仓促上线
  • 原文地址:https://www.cnblogs.com/Hsiung123/p/13812025.html
Copyright © 2020-2023  润新知