PAT 1047. Student List for Course (25)

本文介绍了一个用于生成特定课程的学生列表的C++程序。该程序通过读取学生的ID并将其分配到相应的课程中,然后对每个课程的学生列表进行排序。最终输出每门课程及其学生名单,适用于需要高效处理大量学生数据的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >




//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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值