一、技术总结

  1. 这里由于复杂度的限制,只能够使用vector,然后进行字符串转化:考虑到string、cin、cout会超时,可以使⽤用hash(262626*10+10)将学⽣生姓名变为int型,然后存储在vector里
  2. 这里出了一个巨大的问题,就是审题不清导致最后格式结果不正确。
  3. 还有就是空格输出问题,要注意前面是否已经有输出了。
  4. 还有就是字符串转化成int存储,hash列表的应用,空间换时间
int getID(char name[]){
int id = 0;
for(int i = 0; i < strlen(name); i++){
id = 26*id + (name[i] - 'A');
}
return id;
}

二、参考代码

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
const int N = 40010;
const int M = 26*26*26*10 + 1;
vector<int> selectCourse[M];
int getID(char name[]){
int id = 0;
for(int i = 0; i < 3; i++){
id = id*26 + (name[i] - 'A');
}
id = id*10 + (name[3] - '0');
return id;
}
int main(){
int n,k,id = 0;
char name[5];
cin >> n >> k;
for(int i = 0; i < k; i++){
int coursenum, number;
scanf("%d%d", &coursenum, &number);
for(int j = 0; j < number; j++){
scanf("%s", name);
id = getID(name);
selectCourse[id].push_back(coursenum);
}
}
/*
for(int i = 0; i < n; i++) {
scanf("%s", name);
id = getID(name);
sort(selectCourse[id].begin(),selectCourse[id].end());
printf("%s %lu", name, selectCourse[id].size());
for(int j = 0; j < selectCourse[id].size(); j++)
printf(" %d", selectCourse[id][j]);
printf("\n"); }
return 0;
*/
char str[n+1][5];
for(int i = 0; i < n; i++){
scanf("%s", str[i]);
}
for(int i = 0; i < n; i++){
int id = getID(str[i]);
sort(selectCourse[id].begin(), selectCourse[id].end());
printf("%s %d", str[i], selectCourse[id].size());
for(int j = 0; j < selectCourse[id].size(); j++){
//if(j != 0) printf(" ");
printf(" %d", selectCourse[id][j]); }
printf("\n");
}
return 0; }

A1039 Course List for Student (25 分)的更多相关文章

  1. PAT 甲级 1039 Course List for Student (25 分)(字符串哈希,优先队列,没想到是哈希)*

    1039 Course List for Student (25 分)   Zhejiang University has 40000 students and provides 2500 cours ...

  2. 1039 Course List for Student (25分)

    Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists o ...

  3. PAT 1039 Course List for Student (25分) 使用map<string, vector<int>>

    题目 Zhejiang University has 40000 students and provides 2500 courses. Now given the student name list ...

  4. 【PAT甲级】1039 Course List for Student (25 分)(vector嵌套于map,段错误原因未知)

    题意: 输入两个正整数N和K(N<=40000,K<=2500),分别为学生和课程的数量.接下来输入K门课的信息,先输入每门课的ID再输入有多少学生选了这门课,接下来输入学生们的ID.最后 ...

  5. 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 ...

  6. PAT 甲级 1083 List Grades (25 分)

    1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed ...

  7. 1109 Group Photo (25 分)

    1109 Group Photo (25 分) Formation is very important when taking a group photo. Given the rules of fo ...

  8. 1012 The Best Rank (25 分)

    1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...

  9. 1036 Boys vs Girls (25 分)

    1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of ...

随机推荐

  1. A bean with that name has already been defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class] and overriding is disabled

    2019-12-19 13:26:17.594 WARN [main] o.s.boot.web.servlet.context.AnnotationConfigServletWebServerApp ...

  2. python logging模块“另一个程序正在使用此文件,进程无法访问。”问题解决办法

    在多进程下使用python的logging模块,经常会遇到"另一个程序正在使用此文件,进程无法访问."的错误. 解决办法: https://github.com/Preston-L ...

  3. CF582E Boolean Function(DP,状态压缩,FMT)

    简单题. 我第二道自己做出来的 2900 没毛病,我没切过 2800 的题 lqy:"CF 评分 2800 是中等难度" 我活个啥劲啊 为了方便(同时压缩状态个数),先建出表达式树 ...

  4. JWT的优点和实现Token认证的安全问题

    JWT的优点和实现Token认证的安全问题 一.什么是JWT JWT——Json web token  是为了在网络应用环境间传递声明而执行的一种基于JSON的开放标准,可实现无状态.分布式的Web应 ...

  5. umi+dva+antd新建项目(亲测可用)

    首先全局安装dva+umiumi:npm install -g umidva:npm install -g dva-cli 通过脚手架创建项目 一: mkdir myapp && cd ...

  6. Docker的入门及常用命令

    Docker入门及常用命令 1. 各个容器之间是相互隔离状态: 这样减少了我们软件之间的影响. 2. docker是os层虚拟化架构的一种产品体现, os层虚拟化架构出来的操作系统需要和宿主机操作系统 ...

  7. Java设计模式:Builder(构建器)模式

    概念定义 Builder模式是一步一步创建一个复杂对象的创建型模式.该模式将构建复杂对象的过程和它的部件解耦,使得构建过程和部件的表示隔离开来. 应用场景 对象创建过程比较复杂,或对创建顺序或组合有依 ...

  8. tensorflow查看使用的是cpu还是gpu

    https://stackoverflow.com/questions/38009682/how-to-tell-if-tensorflow-is-using-gpu-acceleration-fro ...

  9. java高并发系列 - 第3天:有关并行的两个重要定律

    有关为什么要使用并行程序的问题前面已经进行了简单的探讨.总的来说,最重要的应该是处于两个目的. 第一,为了获得更好的性能: 第二,由于业务模型的需要,确实需要多个执行实体. 在这里,我将更加关注第一种 ...

  10. Python打包成exe文件很难?一分钟即可学会,并添加图标!

    环境1.python 3.72.pyinstaller下载方式:2.1 python安装(略)2.2 安装pyinstaller打开DOS窗口输入以下命令:pip install pyinstalle ...