0006容器之multimap

#include <list>                                                                                                                                                                                                  
#include<iostream>
#include<vector>
#include<stdexcept>
#include<string>
#include<cstdlib>//abort()
#include<cstdio>//snprintf();整数转字符
#include<ctime>
#include<algorithm>
#include<array>
#include<string>
#include <set>
#include <map>

using namespace std;
//cout << "毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;
#define NUM 1000000

int main()
{
  multimap<long,string> c;
  char buf[10];

  clock_t timeStart = clock();

  for (long i = 0; i < NUM; ++i)
  {
      snprintf(buf, 10, "%d", rand());
      c.insert(pair<long,string>(i,buf));
  }
  cout << "毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;
  cout << "multimap.size() = " << c.size() << endl;
  cout << "multimap.max_size()= " << c.max_size() << endl;

  long target = 66666;
  timeStart = clock();

  auto pItem = c.find(target);
  cout << "c.find() 毫秒: " << (double((clock() - timeStart))/CLOCKS_PER_SEC * 1000 ) << endl;

  if (pItem != c.end())
  {
      cout << "find value: " << (*pItem).second << endl;
  }
  else
  {
      cout << "not find " << endl;
  }

  return 0;
}

posted @ 2023-04-14 08:07  test369  阅读(8)  评论(0编辑  收藏  举报