PAT_1039. Course List for Student
来源:互联网 发布:怎么添加网络打印机 编辑:程序博客网 时间:2024/05/17 01:26
//// main.cpp// PAT_1039. Course List for Student//// Created by wjq on 17/5/7.// Copyright © 2017年 wjq. All rights reserved.//#include <iostream>#include <algorithm>#include <map>#include <vector>using namespace std;vector<int> v;map <int,vector<int> > m;int numOfStudents,numOfLessons;int LessonId,numOfLessonStudents;int name;char temp[100];int hashname(char *name){ return (name[0]-'A')*26*26*10+(name[1]-'A')*26*10+(name[2]-'A')*10+(name[3] - '0');}int main(int argc, const char * argv[]){ scanf("%d%d",&numOfStudents,&numOfLessons); for(int i=0;i<numOfLessons;i++) { scanf("%d%d",&LessonId,&numOfLessonStudents); for(int j=0;j<numOfLessonStudents;j++) { scanf("%s",temp); name=hashname(temp); m[name].push_back(LessonId); } } for(int i=0;i<numOfStudents;i++) { scanf("%s",temp); name=hashname(temp); sort(m[name].begin(),m[name].end()); cout<<temp<<" "<<m[name].size(); for(int j=0;j<m[name].size();j++) cout<<" "<<m[name][j]; cout<<endl; } return 0;}
自己写用的mapran然后最后一个case没过,参考了一位博主的代码,发现原来题目中的名字格式是可以hash的!!!这样就不需要字符串的很多操作了..
以后遇到与标准格式的字符串处理的东西记得hash成数字!
0 0
- PAT_1039: Course List for Student
- PAT_1039. Course List for Student
- Course List for Student
- Student List for Course
- 1047. Student List for Course
- 1039. Course List for Student
- 1039. Course List for Student
- 1047. Student List for Course
- 1039. Course List for Student
- 1047. Student List for Course
- 1039.Course List for Student
- 1047.Student List for Course
- pat1047 Student List for Course
- pat1039 Course List for Student
- 1039. Course List for Student
- 1047. Student List for Course
- 1039 Course List for Student
- 1047 Student List for Course
- PS制作水彩效果
- 动态规划16
- ZooKeeper常见问题整理
- Ambari的架构与设计思想
- 面试总结 —— 高级JAVA工程师
- PAT_1039. Course List for Student
- Linux环境下NodeJS的安装配置
- 测试python代码
- 数据库语法
- 动态规划18
- 你足够了解Context吗
- seckill配置补发
- java设计模式——单件模式
- windoms下AndroidStudio上配置Git和GitHub