与Pat1039题类似
http://blog.csdn.net/andyyang0212/article/details/43495013
用cin、cout超时,改成scanf和printf过了
#include<iostream>
#include<vector>
#include<algorithm>
#define SIZE 2500
using namespace std;
vector <int> course[SIZE];
int hashname(char str[]){
return (str[0] - 'A') * 26 * 26 * 10 + (str[1] - 'A') * 26 * 10 + (str[2] - 'A') * 10 + (str[3] - '0');
}
char name[5];
char *rehashname(int value){
name[0] = value / (26 * 26 * 10) + 'A';
value -= (name[0] - 'A') * 26 * 26 * 10;
name[1] = value / (26 * 10) + 'A';
value -= (name[1] - 'A') * 26 * 10;
name[2] = value / 10 + 'A';
value -= (name[2] - 'A') * 10;
name[3] = value + '0';
name[4] = '\0';
return name;
}
int main(){
freopen("1.in", "r", stdin);
int NumOfStu, NumOfCourse, i,j,EachStuCour,index;
scanf("%d%d", &NumOfStu, &NumOfCourse);
//cin >> NumOfStu >> NumOfCourse;
char name[5];
for (i = 0; i < NumOfStu; i++){
//cin >> name>>EachStuCour;
scanf("%s%d", name, &EachStuCour);
for (j = 0; j < EachStuCour; j++)
{
scanf("%d", &index);
//cin >> index;
course[index - 1].push_back(hashname(name));
}
}
vector<int>::iterator k;
for (i = 0; i < NumOfCourse; i++){
//cout << i + 1 <<" " <<course[i].size() << endl;
printf("%d %d\n", i + 1, course[i].size());
sort(course[i].begin(), course[i].end());
for (k = course[i].begin(); k != course[i].end(); k++)
//cout << rehashname(*k) << endl;
printf("%s\n", rehashname(*k));
}
return 0;
}