1047. Student List for Course (25)

原创 2015年11月20日 13:45:19

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


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

PAT (Advanced Level) Practise 1047 Student List for Course (25)

1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 ...

PAT A 1047.Student List for Course (25)

题目

1047. Student List for Course (25)

Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course li...
  • zjujqq
  • zjujqq
  • 2013年08月28日 00:20
  • 443

1047. Student List for Course (25)-PAT甲级真题

1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 cou...
  • liuchuo
  • liuchuo
  • 2016年08月08日 20:25
  • 129

PAT A1047. Student List for Course (25)

Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course li...
  • jolivan
  • jolivan
  • 2017年02月20日 21:24
  • 77

浙江大学PAT_甲级_1047. Student List for Course (25)

题目链接:点击打开链接 Zhejiang University has 40000 students and provides 2500 courses. Now given the reg...

PAT (Advanced Level) 1047. Student List for Course (25) 哈希,排序,string与char数组的转换

Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course li...

【PAT】1047. Student List for Course (25)

题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1047 题目描述: Zhejiang University has 40000 stu...

pat-a1047. Student List for Course (25)

又是卡时题。。和之前做过一个题反过来而已。。我看时间扩大了一倍以为不卡时用string和map。。超时没话说。。我换了hash后还是超。用的map.改成vector record[maxn]过了。。以...

1047. Student List for Course 解析

按照学生的选课情况,输出这门课有哪些学生上,并按字幕顺序输出。 注意,无论这个课有没有人上都要打印课程号和人数。 这个题通过对学生姓名的处理有两种方法。 一种是用字符数组来存名字,来避免stri...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:1047. Student List for Course (25)
举报原因:
原因补充:

(最多只允许输入30个字)