链表_A1032 Sharing (25 分)

https://pintia.cn/problem-sets/994805342720868352/problems/994805460652113920

/*
*链表的处理
*1.定义静态链表,结构体数组
*2.初始化falg为false
*3.从链表首地址begin遍历,并标记有效结点
*4.对结点排序,有效结点true大于false
*/
#include<iostream>
using namespace std;
#include<cstdio>
const int MAXN=100010;

struct Node {
    char data;
    int next;
    bool flag;
}node[MAXN];

int main() {
    for(int i=0;i<MAXN;i++) {
        node[i].flag=false;
    }
    int address1,address2,num;
    scanf("%d%d%d",&address1,&address2,&num);
    int address,next;
    char data;
    for(int i=0;i<num;i++) {
        scanf("%d %c %d",&address,&data,&next);
        node[address].data=data;
        node[address].next=next;
    }
    int pointer;
    for(pointer=address1;pointer != -1;pointer=node[pointer].next) {
        node[pointer].flag=true; //枚举第一条链表结点并置为true
    }
    for(pointer=address2;pointer != -1;pointer=node[pointer].next) {
        if(node[pointer].flag==true) break; //找到共用结点
    }
    if(pointer != -1) {
        printf("%05d\n",pointer);
    }else {
        printf("-1\n");
    }
    return 0;
}

原文地址:https://www.cnblogs.com/2o2o/p/11371407.html

时间: 2024-10-02 23:42:47

链表_A1032 Sharing (25 分)的相关文章

【PAT甲级】1032 Sharing (25分)

1032 Sharing (25分) To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example, loading and being are stored a

1032 Sharing (25分)(数组链表)

To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For example, loading and being are stored as showed in Figure

PAT Basic 1075 链表元素分类 (25 分)

给定一个单链表,请编写程序将链表元素进行分类排列,使得所有负值元素都排在非负值元素的前面,而 [0, K] 区间内的元素都排在大于 K 的元素前面.但每一类内部元素的顺序是不能改变的.例如:给定链表为 18→7→-4→0→5→-6→10→11→-2,K 为 10,则输出应该为 -4→-6→-2→7→0→5→10→18→11. 输入格式: 每个输入包含一个测试用例.每个测试用例第 1 行给出:第 1 个结点的地址:结点总个数,即正整数N (≤):以及正整数K (≤).结点的地址是 5 位非负整数,

L2-002 链表去重 (25 分)

错误代码,写了一个多小时还是错的,而且只有两分,悲伤逆流成河 #include <iostream> #include <map> #include <stdio.h> #include <math.h> #include <algorithm> using namespace std; map<int,int>mp; typedef struct List { int ard,data,nard; struct List *next

PAT1075-----链表元素分类 (25分)

1075 链表元素分类 (25分) 输入样例: 00100 9 10 23333 10 27777 00000 0 99999 00100 18 12309 68237 -6 23333 33218 -4 00000 48652 -2 -1 99999 5 68237 27777 11 48652 12309 7 33218 输出样例: 33218 -4 68237 68237 -6 48652 48652 -2 12309 12309 7 00000 00000 0 99999 99999 5

1032. Sharing (25)【链表】——PAT (Advanced Level) Practise

题目信息 1032. Sharing (25) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix.

PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)

1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, y

pat1032. Sharing (25)

1032. Sharing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if the

【PAT甲级】1052 Linked List Sorting (25分)

1052 Linked List Sorting (25分) A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, yo