unordered_set:自动删除重复元素,使得集合内元素各不相同
unordered_set<int> q;
q.insert(1);
q.insert(2);
q.insert(1);
q.insert(1);
q.insert(1);
cout << q.size() << endl;
// 2
q.erase(1);
q.find(1);
unordered_set是一个集合,有的时候我们需要一个字典,就是保存一系列key/value对,并且可以按key来查询。比如我们要保存很多同学的成绩,每位同学有一个学号,也有一个分数,我们想按学号迅速查到成绩。这时候我们就可以用unordered_map。
unor
unordered_map<string , int > q;
q.insert(make_pair("ccc",1));
q.insert(make_pair("ttt",2));
q.insert(make_pair("hhh",3));
q.insert(make_pair("hhh",4));
q.insert(make_pair("hhh",5));
cout << q.size() <<endl;
// 3
auto it = q.find("hhh");
cout << it->first << ' ' << it -> second << endl;
// hhh 3