标签:bit cto pause png info scan 技术 排序 end
#include <bits/stdc++.h> #include<math.h> #include <string> using namespace std; const int N = 40005; //vector<vector<int>> 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(){ char name[5]; int n,k; scanf("%d%d",&n,&k); for(int i=0;i<k;++i){ int course,x; scanf("%d%d",&course,&x); for(int j=0;j<x;++j){ scanf("%s",name); int id = getID(name); selectCourse[id].push_back(course); } } for(int i =0;i<n;++i){ scanf("%s",name); int id = getID(name); sort(selectCourse[id].begin(),selectCourse[id].end());//从小到大排序 printf("%s %d",name,selectCourse[id].size());//姓名,选课数 for(int j=0;j<selectCourse[id].size();++j){ printf(" %d",selectCourse[id][j]); } printf("\n"); } system("pause"); return 0; }
C++ STL vector A1039 Course List for Student
标签:bit cto pause png info scan 技术 排序 end
原文地址:https://www.cnblogs.com/JasonPeng1/p/12198206.html