zoukankan      html  css  js  c++  java
  • PAT A1097 Deduplication on a Linked List (25分)

    测试点2是重复数字的链表为空,此时不需要输出-1,所以需要把seq处理包装起来
    而如果第一个非重复链表为空,需要输出-1

    #include<cstdio>
    #include<vector>
    #include<set>
    #include<algorithm>
    using namespace std;
    const int N = 100010;
    struct Node{
        int address,key,next;
        bool isvis = false;
    }node[N];
    set<int> hasabs;
    vector<int> sepadd;//存放不要的地址
    int main(){
        int n,start;
        scanf("%d %d",&start,&n);
        int waitaddress;
        for(int i = 0;i<n;i++){
            int taddress,tkey,tnext;
            scanf("%d %d %d",&taddress,&tkey,&tnext);
            node[taddress].address = taddress;
            node[taddress].key = tkey;
            node[taddress].isvis = true;
            node[taddress].next = tnext;
        }
        int count =1;
        while(start!=-1){
            if(hasabs.find(abs(node[start].key))==hasabs.end()){
                if(count!=1) printf("%05d
    ",start);//保留5位
                hasabs.insert(abs(node[start].key));
                printf("%05d %d ",start,node[start].key);
                
            }else{
                sepadd.push_back(node[start].address);
            }
            start = node[start].next;
            count++;
        }
        printf("-1
    ");
        //处理sep
        if(sepadd.size()!=0){
            count = 1;
            for(int i = 0;i<sepadd.size();i++){
                if(count!=1) printf("%05d
    ",sepadd[i]);
                printf("%05d %d ",sepadd[i],node[sepadd[i]].key);
                count++;
            }
            printf("-1
    ");        
        }
    
        return 0;
    }
    
  • 相关阅读:
    jquery+NHibernate3.3.3+MVC的分页效果
    An exception occurred during configuration of persistence layer.
    StringHelpers
    发送带有认证信息的HTTP请求并取回响应
    script的defer和async
    location.origin兼容
    写法导致的兼容性问题
    正则表达式应用收集
    列表数字对齐布局
    轮盘赌算法
  • 原文地址:https://www.cnblogs.com/shuibeng/p/13599699.html
Copyright © 2011-2022 走看看