首页 > 其他 > 详细

1039. Course List for Student

时间:2015-03-04 12:57:23      阅读:259      评论:0      收藏:0      [点我收藏+]

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 course i, first the course index i and the number of registered students Ni (<= 200) are given in a line. Then in the next line, Ni student 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 201
typedef 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

原文:http://blog.csdn.net/lchinam/article/details/44058323

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!