1039. Course List for Student

Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive integers: N (<=40000), the number of students who look for their course lists, and K (<=2500), the total number of courses. Then the student name lists are 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 Ni(<= 200) are given in a line. Then in the next line, Nistudent names are given. A student name consists of 3 capital English 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 are 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 registered courses of that student, and finally the indices of the courses in increasing order. The query results must be printed in the same order as input. All the data in a line must be separated by a space, with no extra space at the end of the line.

最后一个测试运行超时,,我也不想优化了……

#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].name)==0){student.push_back(i);break;}}}}

懂得接受失败的人,就是懂得人生真谛的人,

1039. Course List for Student

相关文章:

你感兴趣的文章:

标签云: