Siukwan Program

http://siukwan.sinaapp.com/

1047. Student List for Course (25)

1.和前面的1039 Course List for Student (25) 相类似

2.刚开始使用vector<set<int>> 格式存储course,后面在输入数据的时候就已经超时

3.随后改为vector<vector<int>> 存储,在后面进行sort,没有超时


AC代码如下:

//#include<string>
//#include <iomanip>
#include<vector>
#include <algorithm>
//#include<stack>
#include<set>
#include<queue>
#include<map>
//#include<unordered_set>
#include<unordered_map>
//#include <sstream>
//#include "func.h"
//#include <list>
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory.h>
#include<limits.h>
using namespace std;

int main(void)
{
	int studentSum, courseSum;
	scanf("%d %d", &studentSum, &courseSum);
	char name[5];
	vector<vector<int>> course(courseSum);
	int *courseIdx = new int[20];
	int nameInt;
	int chooseSum;
	for (int i = 0; i<studentSum; i++)
	{
		scanf("%s", name);
		nameInt = (name[0] - 'A') * 26 * 26 * 10 + (name[1] - 'A') * 26 * 10 + (name[2] - 'A') * 10 + (name[3] - '0');
		scanf("%d", &chooseSum);
		for (int j = 0; j<chooseSum; j++)
		{
			scanf("%d", &courseIdx[j]);
			course[courseIdx[j] - 1].push_back(nameInt);
		}
	}
	for (int i = 0; i<course.size(); i++)
	{
		printf("%d %d\n", i + 1, course[i].size());
		sort(course[i].begin(), course[i].end());
		for (vector<int>::iterator ite = course[i].begin(); ite != course[i].end(); ite++)
		{
			name[4] = 0;
			name[3] = (*ite) % 10 + '0';
			name[2] = ((*ite) / 10) % 26 + 'A';
			name[1] = ((*ite) / 10 / 26) % 26 + 'A';
			name[0] = ((*ite) / 10 / 26 / 26) + 'A';
			printf("%s\n", name);
		}
	}

	return 0;
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jmlikun/article/details/49946445
文章标签: 哈希 stl vector
个人分类: PAT
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

1047. Student List for Course (25)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭