Advertisement
RobertDeMilo

WB2.12 Множества 2

Sep 4th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. void PrintSet(const set <string>& s)
  9. {
  10.     cout << "Size = " << s.size() << endl;
  11.  
  12.     for (auto x : s) // перестали копировать очередную пару ключ - значение в переменную item c помощью константной ссылки
  13.     {
  14.         cout << x << endl;
  15.     }
  16. }
  17.  
  18. int main()
  19. {
  20.     set<string> month_names = { "January", "March", "February", "March" };
  21.     set<string> other_month_names = { "March", "January", "February" };
  22.    
  23.     cout << (month_names == other_month_names) << endl;     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  24.  
  25.     //cout << month_names.count("January") << endl;
  26.  
  27.     map<string, int> months = { {"January", 1}, {"February", 2}};
  28.     //cout << months.count("January") << endl;
  29.  
  30.     vector<string> v = { "a", "b", "a" };
  31.     set<string> s(begin(v), end(v));
  32.     PrintSet(s);
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement