1039 Course List for Student
哈哈哈哈!!!
会STL的好处完全体现在了这类题目上!!!简直不要太爽!!!
STL:unordered_map<string,set<int> > ans;
auto智能指针
#include"iostream" #include"unordered_map" #include"set" using namespace std; int main() { int n,k; scanf("%d%d",&n,&k); unordered_map<string,set<int> > ans; for(int i = 0; i < k; ++i) { int course_index,stuNum; scanf("%d%d",&course_index,&stuNum); for(int j = 0; j < stuNum; ++j) { string name; cin>>name; ans[name].insert(course_index); } } for(int i = 0; i < n; ++i) { string name; cin>>name; cout<<name<<" "<<ans[name].size(); for(auto it = ans[name].begin(); it != ans[name].end(); ++it) { printf(" %d",*it); } printf("\n"); } }