1047. Student List for Course (25)
来源:互联网 发布:新淘宝店铺开了没人买 编辑:程序博客网 时间:2024/05/01 14:24
考察倒排索引
注意如果用string的话会超时,因为string的copy时间以及比较时间都要比char数组的相应操作更耗时
#include<iostream>#include<vector>#include<string.h>#include<algorithm>typedef struct Student {char name[20];}Student;std::vector<Student> sVec;bool cmp(int s1, int s2){return strcmp(sVec[s1].name, sVec[s2].name) < 0;}int main(){int s, c;while(scanf("%d%d",&s,&c)!=EOF){std::vector<std::vector<int>> cVec(c);sVec.resize(s);//input for(int i = 0; i < s; ++i){int k;scanf("%s %d",sVec[i].name, &k);while(k--){int cid;scanf("%d",&cid);cVec[cid-1].push_back(i);}}//sort and outputfor(int i = 0; i < (int)cVec.size(); ++i){printf("%d %d\n",i+1, (int)cVec[i].size());std::sort(cVec[i].begin(), cVec[i].end(), cmp);for(int j = 0; j < (int)cVec[i].size(); ++j){printf("%s\n",sVec[cVec[i][j]].name);}}}return 0;}
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)-PAT
- 1047. Student List for Course (25)
- 【PAT】1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- PAT 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- PAT 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 1047. Student List for Course (25)
- 双绞线
- Hibernate三种状态以及save、update和saveOrUpdate
- cocos2dx-新建工程时避免文件和文件夹的拷贝
- JAVA 多线程-死锁
- android MotionEvent.obtain模拟事件,自动触发
- 1047. Student List for Course (25)
- 学习:java设计模式—Bridge模式
- android精髓啊
- C++实现最小堆(binary heap)
- 常用 Java 静态代码分析工具的分析与比较
- cocos2dx-mac下 cocos2dx 移植到android平台
- 1048. Find Coins (25)
- 学习:java设计模式—Iterator模式
- XTU 1150 Assembly Line