1.
#include <iostream>
#include <unordered_map>
#include <string>
#include <time.h>
using namespace std;
int main()
{
vector<int> vec;
vec.reserve(100000);
srand(time(0));
for (int i = 0; i < 100000; ++i)
{
vec.push_back((rand() % 1000000) + 1);
}
unordered_map<int, int> map;
vector<int>::iterator it = vec.begin();
unordered_map<int, int>::iterator mapit;
for (; it != vec.end(); ++it)
{
mapit = map.find(*it);
if (mapit != map.end())
{
mapit->second += 1;
}
else
{
map[*it] = 1;
}
}
mapit = map.begin();
for (; mapit != map.end(); ++mapit)
{
if (mapit->second > 1)
{
cout << mapit->first << "->" << mapit->second << endl;
}
}
cout << endl;
return 0;
}
![](https://i-blog.csdnimg.cn/blog_migrate/15503fd4e08a11e47befd0e48ec9d7ab.png)