Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course list of each student and you is supposed to output the student name lists of all the courses .
Input Specification:
Each input file contains the one test case. The first line contains 2 numbers:n (<=40000), the total number of students, and K (<=2500), the Tot Al Number of courses. Then N lines follow, each contains a student ' s name (3 capital 中文版 letters plus a one-digit number), a positive number C (<=20) which is the number of courses that this student have registered, and then followed by C course numbers. For the sake of simplicity, the courses is numbered from 1 to K.
Output Specification:
For each test case, print the student name lists of the courses in increasing order of the course numbers. For each course, first print on one line the course number and the number of registered students, separated by a space. Then output the students ' names in alphabetical order. Each name is occupies a line.
Sample Input:
5zoe1 2 4 5ann0 3 5 2 1bob5 5 3 4 2 1 5joe4 1 2jay9 4 1 2 5 4fra8 3 4 2 5don2 2 4 5amy7 1 5KAT3 3 5 4 2LOR6 4 2 4 1 5
Sample Output:
1 4ann0bob5jay9lor62 7ann0bob5fra8jay9joe4kat3lor63 1bob54 7bob5don2fra8jay9kat3lor6zoe15 9amy7ann0bob5don2fra8jay9kat3lor6zoe1
1#include <stdio.h>2#include <stdlib.h>3#include <iostream>4#include <string.h>5#include <string>6#include <math.h>7#include <algorithm>8#include <vector>9 using namespace std;Ten Const intmaxn=40010; One Const intmaxc=2510; A - CharName[maxn][5]; -vector<int>COURSE[MAXC]; the -BOOL CMP (intAintb) - { - returnstrcmp (Name[a],name[b]) <0; + } - + intMain () { A intn,k; atscanf ("%d%d",&n,&k); - for(inti=0;i<n;i++) - { -scanf ("%s", Name[i]); - intR; -scanf ("%d",&R); in for(intj=0;j<r;j++) - { to inttemp; +scanf ("%d",&temp); - Course[temp].push_back (i); the } * } $ for(inti=1;i<=k;i++)Panax Notoginseng { - sort (Course[i].begin (), Course[i].end (), CMP); theprintf ("%d%d\n", I,course[i].size ()); + for(intJ=0;j<course[i].size (); j + +) A { theprintf ("%s\n", Name[course[i][j]]); + } - } $ $ return0; -}
A1047. Student List for Course (25)