1047. Student List for Course (25)
2015-12-06 10:59
477 查看
时间限制400 ms
内存限制64000 kB
代码长度限制16000 B
判题程序Standard作者CHEN, Yue
Zhejiang University has 40000 students and provides 2500 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 (<=40000), the total number of students, and K (<=2500), 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 (<=20) 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:
[/code]
来自为知笔记(Wiz)
内存限制64000 kB
代码长度限制16000 B
判题程序Standard作者CHEN, Yue
Zhejiang University has 40000 students and provides 2500 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 (<=40000), the total number of students, and K (<=2500), 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 (<=20) 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 5Sample 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来源: <http://www.patest.cn/contests/pat-a-practise/1047>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
#pragma warning(disable:4996)
using namespace std;
struct Lesson
{
vector<int> students;
};
vector<Lesson> l;
int main(void) {
int n, k;
cin >> n >> k;
for (int i = 0; i <= k; i++) {
Lesson ltemp;
l.push_back(ltemp);
}
char name[5];
int numofClass;
int classnum;
for (int i = 0; i < n; i++) {
//cin >> name >> numofClass;
scanf("%s", name);
scanf("%d", &numofClass);
for (int j = 0; j < numofClass; j++) {
//cin >> classnum;
scanf("%d", &classnum);
int namecode = (name[0] - 'A') * 26 * 26 * 26 + (name[1] - 'A') * 26 * 26 + (name[2] - 'A') * 26 + name[3] - '0';
l[classnum].students.push_back(namecode);
}
}
for (int i = 1; i <= k; i++) {
//cout << i << " " << l[i].students.size() << endl;
printf("%d %d\n", i, l[i].students.size());
sort(l[i].students.begin(), l[i].students.end());
for (int j = 0; j < l[i].students.size(); j++) {
//cout << l[i].students[j]<<endl;
char a[5];
a[0] = l[i].students[j] / 17576+'A';
l[i].students[j] %= 17576;
a[1] = l[i].students[j] / 676+'A';
l[i].students[j] %= 676;
a[2] = l[i].students[j] / 26+'A';
l[i].students[j] %= 26;
a[3] = l[i].students[j] % 10+'0';
a[4] = '\0';
printf("%s\n", a);
}
}
return 0;
}
[/code]
来自为知笔记(Wiz)
相关文章推荐
- 1046. Shortest Distance (20)
- 协议模糊测试
- 【C语言提高26】二级指针做输入的第三种内存模型:手工打造二维内存
- Android触摸事件处理机制之requestDisallowInterceptTouchEvent
- java小说上传到txt功能实现(相同的小说不能再次添加)
- 干式双离合和湿式双离合的优缺点
- 1045. Favorite Color Stripe (30)
- 斯坦福大学机器学习课程原始讲义(含公开课视频) (转载)
- Android@id和@+id区别
- MySql重装或者重新配置数据库实例时遇到“本地计算机无法启动Mysql服务”错误的解决方法
- layout设置出现和隐藏动画
- PAT乙级 数素数 (20)
- Boxfilter 块滤波器
- 1044. Shopping in Mars (25)
- JAVA编程思想导论(猜字谜游戏1.0)
- python核心编程-reduce函数
- NOIP2015提高组Day1斗地主
- 黑马程序员——OC学习——Category
- JavaScript基础——理解变量作用域
- css 的base类