Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you is supposed to output the registered course list for each Studen T who comes for a query.
Input Specification:
Each input file contains the one test case. The first line contains 2 positive integers:n (<=40000), the number of students SE lists, and K (<=2500), the total number of courses. Then the student name lists is given for the courses (numbered from 1 to K) in the following format:for each courseI, first the course indexIAnd the number of registered students N i (<=) is given in a line. Then on the next line, Ni student names is given. A student name consists of 3 capital 中文版 letters plus a one-digit number. Finally The last line contains the N names of students who come for a query. All the names and numbers in a line is separated by a space.
Output Specification:
For each test case, print your results in N lines. Each line corresponds to one student, in the following Format:first print the student's name, then the total number of RE Gistered courses of that student, and finally the indices of the courses in increasing order. The query results must is printed in the same order as input. All the data in a line must is separated by a space, with no extra space at the end of the line.
The last Test run timed out, and I don't want to optimize it ...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <vector>using namespace std ; #define N 201typedef struct{Char name[5]; }student;void Find (char * a);vector<student> course[n];vector<int> student;int n,k;int main () {int i,j; scanf ("%d%d", &n,&k); int num,id; Student temp; for (i=0;i<k;i++) {scanf ("%d%d", &id,&num); for (j=0;j<num;j++) {scanf ("%s", temp.name); Course[id].push_back (temp); }} char query[5]; for (i=0;i<n;i++) {scanf ("%s", query); Find (query); printf ("%s", query); if (Student.size () ==0) printf ("0\n"); else {printf ("%d", student.size ()); For (J=0;j<student.size (); j + +) printf ("%d", student[j]); printf ("\ n"); } student.clear (); } system ("Pause"); return 0;}void Find (char * a) {int i,j; for (i=1;i<=k;i++) {for (J=0;j<course[i].size (); j + +) {if (strcmp (a,course[i][j].na Me) {==0) {student.push_back (i); Break } } } }
1039. Course List for Student