Ranking of data structure experiment 7: course selection list

Posted by fr@nkie on Thu, 30 Apr 2020 18:54:26 +0200

Ranking of data structure experiment 7: course selection list
Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic
Problem Description
With the expansion of the school scale, the number of students has increased dramatically, and the output of the course selection list has become a heavy task. At present, our school has more than 30000 students and more than 2000 courses. Please output the course selection list of each course according to the given student course selection list.

Input
Input the first line to give two positive integers N (N ≤ 35000) and M(M ≤ 2000), where N is the total number of students in the whole school, M is the total number of courses, and then give N lines, each line includes two digits (the total length of string is less than 10) after the student'S name Pinyin + student number, and the number S represents the total number of courses selected by the student, followed by S course numbers, which are agreed to be from 1 to m, and the data is separated by spaces.

Output
Output the course number, the total number of students and the list of students according to the increasing order of the course number, and output the list of students according to the dictionary order of their names for the students taking the same course. Data is separated by spaces, and there must be no extra spaces at the end of the line.

Example Input
5 3
Jack01 2 2 3
Jone01 2 1 3
Anni02 1 1
Harry01 2 1 3
TBH27 1 1
Example Output
1 4
Anni02
Harry01
Jone01
TBH27
2 1
Jack01
3 3
Harry01
Jack01
Jone01
Hint

Author
xam

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

const int MAX = 35005;

typedef struct node
{
    char name[15];
    struct node *next;
} node, *pnode;

int main()
{
    int n, m;
    while (~scanf("%d %d", &n, &m))
    {
        int i;
        pnode *list = new pnode[MAX]();
        for (i = 0; i < 2010; i++)//Initialize the space required for all 2000 courses
        {
            list[i] = new node();//
        }
        int *slist = new int[MAX]();
        for (i = 0; i < n; i++)
        {
            char n[15];
            int s;
            scanf("%s %d", n, &s);
            while (s--)
            {
                int t;
                scanf("%d", &t);
                slist[t]++;
                node *q = new node();
                q->next = NULL;
                strcpy(q->name, n);
                node *p = list[t];
                while (p->next)
                {
                    if (strcmp(q->name, p->next->name) < 0)
                        break;
                    p = p->next;
                }
                q->next = p->next;
                p->next = q;
            }
        }
        for (i = 1; i <= m; i++)
        {
            printf("%d %d\n", i, slist[i]);
            node *ptr = list[i]->next;
            while (ptr)
            {
                printf("%s\n", ptr->name);
                ptr = ptr->next;
            }
        }
    }
    return 0;
}

Topics: less