????? ?????????????, ???????????? ????? CyberForum.ru
???? ????????

map - ?????????? ? ???????? - C++

?????
???????????
???????????? ??????
?????? ???? ???????
C++ ????????? ?????????? ????????? ? ?????????? ??????? http://www.cyberforum.ru/cpp-beginners/thread991300.html
???????? ?????? ?????? . ????????? ??????? ????????? ? ?????????? ???????, ????????? ?? ??????? ??? ?????? ????????. ??????? ?????????? ?????????.
C++ ?? ???????? ????? ?????????? ?? ???? ??? ??????? ??? ?? ?????????? ???????? ???????! ??? ????? ???????? http://www.cyberforum.ru/cpp-beginners/thread991284.html
C++ ????????? ???????? ?????????
??????????, ???? ???.
C++ ??? ?????????? ????????????? ??????? ???????? ??????? ?????????? ???????? ?????? ?? ???????????????
?????? 2 ??????, ????????? ?? ????, ??????????? ?????????. ???? ?????? ????? ?????? ?????? ????? ??, ??? ?????? ????? ?????? ??????, ?? ???????? ??????? ?????????? ???????? ?????? ?????? ??...
C++ ????? ??? ?????? ? ?????????? ??????? ?++ http://www.cyberforum.ru/cpp-beginners/thread991193.html
??????? ???????? ? 2 ???????, ? 2 ?????????????? ??? ?????? ? ????????? ??????. ????? ????????? ????, ????????? ?????????? ?????, ???????, ???????, ???????? ?????? ?? ???????? ???????. ???? ??? ?????...
C++ ??????? ?????? ? Visual C++ #include "stdafx.h" #include <iostream> #include <string> #include <stdio.h> #include <conio.h> #include "cstring" #include "clocale" using namespace std; struct student ?????????

???????? ????????? ????????
ForEveR
? ???????
??????? ?++
7979 / 4738 / 321
???????????: 24.06.2010
?????????: 10,543
??????????? ?????: 3
29.10.2013, 13:27
??? ??????? +- ???-?? ???

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdlib>
#include <ctime>
 
int main()
{
   const size_t iterations = 10;
   const size_t max = 20;
   srand(time(0));
   std::map<int, int> values;
   std::vector<int> vec;
   for (size_t i = 0; i < iterations; ++i)
   {
      auto pos = values.insert(std::make_pair(rand() % max, rand() % max));
      if (!pos.second)
      {
         --i;
         continue;
      }
      vec.push_back(rand() % max);
   }
   std::cout << "map keys: ";
   std::for_each(values.begin(), values.end(), [](const std::pair<int, int>& p)
   {
      std::cout << p.first << " ";
   });
   std::cout << std::endl;
   std::cout << "vector: ";
   std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, " "));
   std::cout << std::endl;
   std::vector<int> original(vec);
   vec.erase(std::remove_if(vec.begin(), vec.end(), [&values](int v)
   {
      return values.find(v) == values.end();
   }), vec.end());
   for (std::map<int, int>::const_iterator pos = values.begin(); pos != values.end();)
   {
      if (std::find(original.begin(), original.end(), pos->first) == original.end())
      {
         pos = values.erase(pos);
      }
      else
      {
         ++pos;
      }
   }
   std::cout << "map keys: ";
   std::for_each(values.begin(), values.end(), [](const std::pair<int, int>& p)
   {
      std::cout << p.first << " ";
   });
   std::cout << std::endl;
   std::cout << "vector: ";
   std::copy(vec.begin(), vec.end(), std::ostream_iterator<int>(std::cout, " "));
   std::cout << std::endl;
}
1
 
?????????? - ????? ?????????????, ???????????? ?????, ????????????????
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
???????@Mail.ru