1047 Student List for Course (25分)
Zhejiang University has 40,000 students and provides 2,500 courses. Now given the registered course list of each student, you are supposed to output the student name lists of all the courses.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 numbers: N (≤), the total number of students, and K (≤), the total number of courses. Then N lines follow, each contains a student's name (3 capital English letters plus a one-digit number), a positive number C (≤) which is the number of courses that this student has registered, and then followed by C course numbers. For the sake of simplicity, the courses are numbered from 1 to K.
Output Specification:
For each test case, print the student name lists of all the courses in increasing order of the course numbers. For each course, first print in one line the course number and the number of registered students, separated by a space. Then output the students' names in alphabetical order. Each name occupies a line.
Sample Input:
10 5
ZOE1 2 4 5
ANN0 3 5 2 1
BOB5 5 3 4 2 1 5
JOE4 1 2
JAY9 4 1 2 5 4
FRA8 3 4 2 5
DON2 2 4 5
AMY7 1 5
KAT3 3 5 4 2
LOR6 4 2 4 1 5
Sample Output:
1 4
ANN0
BOB5
JAY9
LOR6
2 7
ANN0
BOB5
FRA8
JAY9
JOE4
KAT3
LOR6
3 1
BOB5
4 7
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1
5 9
AMY7
ANN0
BOB5
DON2
FRA8
JAY9
KAT3
LOR6
ZOE1
用vec
#define _CRT_SECURE_NO_WARNINGS
#include <climits>
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int N, K;
vector<string> V[];
bool compare(string& a, string& b)
{
return a < b;
}
int main()
{
scanf("%d%d", &N, &K);
for (int i = ; i < N; i++)
{
char s[];
int C, num;
scanf("%s %d", s,&C);
string name(s);
for (int j = ; j < C; j++)
{
scanf("%d", &num);
V[num].push_back(name);
}
}
for (int i = ; i <= K; i++)
sort(V[i].begin(), V[i].end(), compare);
for (int i = ; i <= K; i++)
{
printf("%d %d\n", i, V[i].size());
for (auto it : V[i])
cout << it<<endl;
}
}
tor就是过不了最后一个测试点
1047 Student List for Course (25分)的更多相关文章
- PAT 甲级 1047 Student List for Course (25 分)(cout超时,string scanf printf注意点,字符串哈希反哈希)
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cou ...
- 【PAT甲级】1047 Student List for Course (25 分)
题意: 输入两个正整数N和K(N<=40000,K<=2500),接下来输入N行,每行包括一个学生的名字和所选课程的门数,接着输入每门所选课程的序号.输出每门课程有多少学生选择并按字典序输 ...
- PAT 解题报告 1047. Student List for Course (25)
1047. Student List for Course (25) Zhejiang University has 40000 students and provides 2500 courses. ...
- 1047. Student List for Course (25)
Zhejiang University has 40000 students and provides 2500 courses. Now given the registered course li ...
- PAT (Advanced Level) 1047. Student List for Course (25)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT甲级题解-1047. Student List for Course (25)-排序
一开始是建立了course[2501][40001]数组,存储每节课的学生编号然后for循环两层输出,但这样复杂度为O(2500*40000),也很明显导致最后时间超时后来发现最多40000学生,每个 ...
- A1047 Student List for Course (25 分)
一.技术总结 首先题目要看清湖,提出的条件很关键,比如for循环的终止条件,特别注意. 还有这个题目主要考虑到vector的使用,还有注意一定要加上using namespace std; 输出格式, ...
- PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*
1039 Course List for Student (25 分) Zhejiang University has 40000 students and provides 2500 cours ...
- PAT 1047 Student List for Course[一般]
1047 Student List for Course (25 分) Zhejiang University has 40,000 students and provides 2,500 cours ...
随机推荐
- python自动化第二课 - python基础2
1.判断奇数偶数 num = input("请输入一个数字,判断是否为偶数:") print(not int(num) % 2) 2.浮点数的高精度计算用Decimal(from ...
- MongoDB复制集概念架构浅析
一.复制集的作用 (1) 高可用 防止设备(服务器.网络)故障. 提供自动failover 功能. 技术来保证数 (2) 灾难恢复 当发生故障时,可以从其他节点恢复. (3) 功能隔离 用于分析.报表 ...
- js实现字符串逆向输出的4种方式
一.第一种方式(利用charAt()这个函数实现) 代码如下: var str="你好世界!!!!"; var str1="";//这里创建一个空字符串用来拼接 ...
- spring boot 学习笔记(一)
学习链接:http://www.cnblogs.com/ityouknow/category/914493.html 定义 spring boot 是由pivotal 团队提供的权限框架,设计目的是用 ...
- ajax5
处理跨域方法 (代理) 一个域名地址的组成: /script/jQuery.js 协议 子域名 主域名 端口号 请求资源地址 当协议,子域名,主域名,端口号中任意一个不相同时,都算作不同 ...
- CentOS7使用tar.gz方法安装php7.2.8
软件:VMware 系统版本:CentOS7 1.检查系统里是否有安装的PHP包,如果有的话先删除 [root@localhost ~]# yum list installed | grep php ...
- Java第一节课考试
1 package kaoshi; import java.util.Scanner; public class ScoreInformation { Scanner input=new Scanne ...
- C# MP3播放帮助类
本文为原创文章如需转载请注明出处: /// <summary> /// ************************************************* /// 类名:M ...
- Gitblit无法查看单个文件解决方案
一个简单的解决方案是在reference.properties中设置: web.mountParameters = false 在这种情况下,您完全避免了该问题,因为项目名称,分支和文件名作为查询字符 ...
- CVE-2019-3396:Confluence未授权模板注入_代码执行
title: Confluence未授权模板注入/代码执行(CVE-2019-3396) tags: [poc,cve] 简介 Confluence是一个专业的企业知识管理与协同软件,也可以用于构建企 ...