【PAT】【Advanced Level】1039. Course List for Student (25)
来源:互联网 发布:高德导航软件 编辑:程序博客网 时间:2024/05/21 19:31
1039. Course List for Student (25)
Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes for a query.
Input Specification:
Each input file contains one test case. For each case, the first line contains 2 positive integers: N (<=40000), the number of students who look for their course lists, and K (<=2500), the total number of courses. Then the student name lists are given for the courses (numbered from 1 to K) in the following format: for each course i, first the course index i and the number of registered students Ni (<= 200) are given in a line. Then in the next line, Ni student names are given. A student name consists of 3 capital English letters plus a one-digit number. Finally the last line contains the N names of students who come for a query. All the names and numbers in a line are separated by a space.
Output Specification:
For each test case, print your results in N lines. Each line corresponds to one student, in the following format: first print the student's name, then the total number of registered courses of that student, and finally the indices of the courses in increasing order. The query results must be printed in the same order as input. All the data in a line must be separated by a space, with no extra space at the end of the line.
Sample Input:11 54 7BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE11 4ANN0 BOB5 JAY9 LOR62 7ANN0 BOB5 FRA8 JAY9 JOE4 KAT3 LOR63 1BOB55 9AMY7 ANN0 BOB5 DON2 FRA8 JAY9 KAT3 LOR6 ZOE1ZOE1 ANN0 BOB5 JOE4 JAY9 FRA8 DON2 AMY7 KAT3 LOR6 NON9Sample Output:
ZOE1 2 4 5ANN0 3 1 2 5BOB5 5 1 2 3 4 5JOE4 1 2JAY9 4 1 2 4 5FRA8 3 2 4 5DON2 2 4 5AMY7 1 5KAT3 3 2 4 5LOR6 4 1 2 4 5NON9 0
https://www.patest.cn/contests/pat-a-practise/1039
https://www.nowcoder.com/pat/5/problem/4026
思路:
少见的卡时间的题目
string、cin/cout、map均不能使用
所以将姓名映射为整数进行判断
CODE:
#include<iostream>#include<cstring>#include<vector>#include<cstdio>#include<algorithm>#define SS 175760using namespace std;typedef struct S{ char* name; vector<int> cou;};int inde[SS];vector<S> stu;int main(){ memset(inde,0,sizeof(inde)); int n,k; scanf("%d%d",&n,&k); int sum=0; for (int i=0;i<k;i++) { int num,m; scanf("%d%d",&num,&m); for (int i=0;i<m;i++) { char* tt=(char *)malloc(4); scanf("%s",tt); int temp=(tt[0]-'A')*26*26*10+(tt[1]-'A')*26*10+(tt[2]-'A')*10+(tt[3]-'0'); if (inde[temp]==0) { S t; t.name=tt; t.cou.push_back(num); stu.push_back(t); sum++; inde[temp]=sum; } else { int te=inde[temp]-1; stu[te].cou.push_back(num); } } } for (int i=0;i<n;i++) { char* tt=(char *)malloc(4); scanf("%s",tt); printf("%s ",tt); int temp=(tt[0]-'A')*26*26*10+(tt[1]-'A')*26*10+(tt[2]-'A')*10+(tt[3]-'0'); if (inde[temp]!=0) { int te=inde[temp]-1; sort(stu[te].cou.begin(),stu[te].cou.end()); printf("%d ",stu[te].cou.size()); for (int j=0;j<stu[te].cou.size()-1;j++) printf("%d ",stu[te].cou[j]); printf("%d\n",stu[te].cou[stu[te].cou.size()-1]); } else { printf("0\n"); } } return 0;}
- 【C++】PAT(advanced level)1039. Course List for Student (25)
- 【PAT】【Advanced Level】1039. Course List for Student (25)
- 【C++】PAT(advanced level)1047. Student List for Course (25)
- PAT (Advanced Level) Practis 1039 Course List for Student (25)
- PAT (Advanced Level) Practise 1047 Student List for Course (25)
- PAT (Advanced Level) Practise 1047 Student List for Course (25)
- PAT (Advanced Level) Practise 1039 Course List for Student (25)
- 【PAT】【Advanced Level】1047. Student List for Course (25)
- PAT (Advanced Level) 1039. Course List for Student (25) 排序,手动写哈希
- 1039. Course List for Student (25)【排序】——PAT (Advanced Level) Practise
- Pat(Advanced Level)Practice--1039(Course List for Student)
- Pat(Advanced Level)Practice--1047(Student List for Course)
- 1047. Student List for Course (25)【排序】——PAT (Advanced Level) Practise
- 1039. Course List for Student (25)-PAT
- PAT 1039. Course List for Student (25)
- PAT 1039. Course List for Student (25)
- PAT 1039. Course List for Student (25)
- PAT 1039. Course List for Student (25)
- js 其他对象
- 二级指针做输入的3种模型-2
- MFC 单文档应用程序如何为状态栏添加进度条
- Linux -bash: java: command not found 解决方法
- HDU 2689 Sort it 树状数组
- 【PAT】【Advanced Level】1039. Course List for Student (25)
- 【算法基础】算法导论-最大子数组问题
- Docker 编排利器-Compose简介
- 2017多校第4场 HDU 6069 Counting Divisors 素筛,暴力,优化
- java静态代码块 构造代码块 构造方法的执行顺序及注意问题
- 二叉树
- Python日常学习记录
- 装饰器
- JS日期,其他对象