PAT:1039. Course List for Student (25) 部分正确(最后一个大数据错误)

#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
using namespace std;
const int MAX=40010;
const int H=26*26*26*10+10;
int n,k;          //n个人,k门课

vector<int> HAR[H];

int getID(char str[])    //获取名字对应的哈希ID
{
  int ID=0;
  for(int i=0 ; i<3 ; ++i)
  {
    ID=ID*26+str[i]+'0';
  }
  ID+=str[3]+'0';
  return ID;
}

int main()
{
  scanf("%d%d",&n,&k);
  for(int i=1 ; i<=k ; ++i)
  {
    int course=0,people=0;
    scanf("%d%d",&course,&people);
    for(int j=0 ; j<people ; ++j)
    {
      char name[5];
      scanf("%s",name);
      int ID=getID(name);
      HAR[ID].push_back(course);
    }
  }
  for(int i=0 ; i<n ; ++i)
  {
    char name[5];
    scanf("%s",name);
    int ID=getID(name);
    sort(HAR[ID].begin(),HAR[ID].end());
    printf("%s %d",name,HAR[ID].size());
    for(int j=0 ; j<HAR[ID].size() ; ++j)
      printf(" %d",HAR[ID][j]);
    printf("\n");
  }

  return 0;
}
posted on 2015-03-10 18:04  Evence  阅读(231)  评论(0编辑  收藏  举报