Advertisement
smatskevich

Lnip3

Mar 19th, 2022
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <string>
  4. #include <unordered_map>
  5.  
  6. int main() {
  7.   std::unordered_map<std::string, int> m;
  8.   m.insert({"Ivan", 5});
  9.   m["Max"] = 5;
  10.   m["Artyom"] = 55;
  11.   std::cout << m["Ivan"] << std::endl;
  12.   std::cout << m["Max"] << std::endl;
  13.   std::cout << m["B"] << std::endl;
  14.   std::cout << m.at("B") << std::endl;
  15.   std::cout << m["A"] << std::endl;
  16.   //  auto it = m.find("Stepa");
  17. //  if (it != m.end()) {
  18. //    it->second = 3;
  19. //  }
  20.   std::cout << m["Stepa"] << std::endl;
  21.  
  22.   std::map<std::string, int> mm;
  23.   mm.insert({"Ivan", 5});
  24.   mm["Max"] = 5;
  25.   mm["Artyom"] = 55;
  26.   std::cout << mm["Ivan"] << std::endl;
  27.   std::cout << mm["Max"] << std::endl;
  28.   std::cout << mm["B"] << std::endl;
  29.   std::cout << mm["A"] << std::endl;
  30.   //  auto it = m.find("Stepa");
  31. //  if (it != m.end()) {
  32. //    it->second = 3;
  33. //  }
  34.   std::cout << mm["Stepa"] << std::endl << std::endl;
  35.  
  36.   std::cout << "Unordered map:" << std::endl;
  37.   for (auto& [key, value] : m) {
  38.     std::cout << key << " " << value << std::endl;
  39.   }
  40.   std::cout << "Map:" << std::endl;
  41.   for (auto& [key, value] : mm) {
  42.     std::cout << key << " " << value << std::endl;
  43.   }
  44.  
  45.   return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement