您的位置:首页 > 其它

PAT 1047. Student List for Course (25)

2015-03-16 08:30 176 查看
//1047. Student List for Course (25)
//受不了cin和cout了,一用就超时了,。。。。。。。。。。
//accept
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

//typedef struct
//{
//	int stu[40005];
//	int total;
//}Course;

int cal(char c[5])
{
int tmp;
tmp = (c[0] - 'A') * 26*26*26 + (c[1] - 'A')*26*26 + (c[2] - 'A')*26 + c[3] - '0';
return tmp;
}

void Print(int t)
{
char i1, i2, i3;
int i4;

i4 = t %26;
t = t / 26;
i3 = t%26 + 'A';
t = t/26;
i2 = t %26+'A';
t = t/26;
i1 = t%26+'A';

printf("%c%c%c%d", i1, i2, i3, i4);
//cout << i1<< i2<<i3<<i4;
}
vector<int> c[2505];
int main()
{
int N, K;
cin >> N >> K;

int i;
char tmp1[5];

int tmp2;
int tmp3;

int j;
for (i = 0;i<N;i++)
{
//cin >> tmp1;
scanf("%s", &tmp1);
int num = cal(tmp1);

scanf("%d", &tmp2);
for (j = 0;j<tmp2;j++)
{
scanf("%d", &tmp3);
c[tmp3].push_back(num);
}
}

for (i = 1;i<=K;i++)
{
sort(c[i].begin(),  c[i].end());
}

for (i = 1;i<=K;i++)
{
//cout << i << " " << c[i].size() << endl;
printf("%d %d\n", i, c[i].size());

for (j = 0;j<c[i].size();j++)
{
Print(c[i][j]);
printf("\n");
//cout << endl;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: