当前位置: 首页 > news >正文

做python项目的网站个人中心html模板

做python项目的网站,个人中心html模板,建设工程包括哪些,海口小程序开发为什么需要map和multimap#xff1a; 1.查找高效#xff1a; 映射类允许通过键快速查找对应的值#xff0c;这对于需要频繁查找特定元素的场景非常适合。 2.自动排序#xff1a; 会自动根据键的顺序对元素进行排序 3.多级映射#xff1a; 映射类可以嵌套使用#xff0c;创… 为什么需要map和multimap 1.查找高效 映射类允许通过键快速查找对应的值这对于需要频繁查找特定元素的场景非常适合。 2.自动排序 会自动根据键的顺序对元素进行排序 3.多级映射 映射类可以嵌套使用创建多级映射这对于复杂的数据结构非常有用 4.键值对存储 映射类专门设计用于存储键值对key-value map 和multimap 之间的区别在于后者能够存储重复的键而前者只能存储唯一的键要使用需要包含头文件map 1.实例化map和multimap map实例化 std::mapkey_type, value_type map_instance; //key_type 是键的类型。 //value_type 是与每个键关联的值的类型。#include iostream #include mapint main() {// 实例化std::map键类型为int值类型为std::stringstd::mapint, std::string myMap;// 向map中添加元素myMap[1] one;myMap[2] two;myMap[3] three;// 打印map和multimap的内容std::cout Map: std::endl;for (const auto pair : myMap) {std::cout pair.first : pair.second std::endl;}// 尝试添加重复的键这将更新已存在的键对应的值myMap[1] ONE; // one 将被 ONE 替换// 打印map的内容std::cout Map: std::endl;for (const auto pair : myMap) {std::cout pair.first : pair.second std::endl;}system(pause);return 0; }multimap实例化 std::multimapkey_type, value_type multimap_instance; //key_type 是键的类型可以有重复。 //value_type 是与每个键关联的值的类型。#include iostream #include mapint main() {// 实例化std::multimap允许有相同键的多个元素std::multimapint, std::string myMultimap;// 向multimap中添加具有相同键的多个元素myMultimap.insert(std::make_pair(1, uno));myMultimap.insert(std::make_pair(1, eins));// 打印multimap的内容std::cout Multimap: std::endl;for (const auto pair : myMultimap) {std::cout pair.first : pair.second std::endl;}system(pause);return 0; }2.在map和multimap中插入元素 使用insert()成员函数插入 //key为键val为值 map.insert(std::make_pair(key,val)); map.insert(std::pairint,string(key,val)); map[key]val;//multimap操作相同但无法使用数组语法[]来插入#include iostream #include map using namespace std;int main() {// 实例化std::multimap允许有相同键的多个元素multimapint, string myMultimap;// 向multimap中添加具有相同键的多个元素myMultimap.insert(make_pair(1, one));myMultimap.insert(pairint,string(1, two));// 打印multimap的内容cout Multimap: endl;for (const auto pair : myMultimap) {cout pair.first : pair.second endl;}//实例化std::mapmapint,string myMap;//向map中添加元素myMap[1]map_one;myMap.insert(make_pair(2,map_two));myMap.insert(pairint,string(3,map_three));// 打印map的内容cout map: endl;for (const auto pair : myMap) {cout pair.first : pair.second endl;}system(pause);return 0; }3.在map和multimap中查找元素 使用find()成员函数该函数会返回一个迭代器 在map中查找 #include map #include iostream #include stringint main() {std::mapint, std::string myMap;myMap[1] one;myMap[2] two;// 查找键为1的元素auto it myMap.find(1);//检查是否查找成功if (it ! myMap.end()) {//myMap.end()指向容器的末尾即最后一个元素之后的位置//如果已经找到了就不会指向这个位置反之则没有找到std::cout Found: it-second std::endl; // 输出 Found: one} else {std::cout Not found std::endl;}// 查找键为3的元素这个键不存在于map中it myMap.find(3);if (it myMap.end()) {std::cout Not found std::endl;}system(pause);return 0; }在multimap中查找 因为mulitimap允许包含多个键相同的键值对所以可以用multimap::count()函数确定有多少个再对迭代器进行递增来访问这些值 #include map #include iostream #include stringint main() {std::multimapint, std::string myMultimap;// 插入具有相同键的不同值的元素myMultimap.insert(std::make_pair(1, one));myMultimap.insert(std::make_pair(1, ONE));myMultimap.insert(std::make_pair(2, two));// 查找键为1的元素auto it myMultimap.find(1);// 如果找到了至少一个元素if (it ! myMultimap.end()) {// 使用count()确定键为1的元素数量size_t count myMultimap.count(1);// 遍历所有具有键为1的元素for (size_t i 0; i count; i) {std::cout it-second ;// 递增迭代器以移动到下一个具有相同键的元素it;}}// 如果没有找到键为1的元素输出Not foundelse {std::cout Not found std::endl;}system(pause);return 0; }4.删除map和multimap中的元素、 使用erase()函数有以下几种版本 删除指定位置的元素 map.erase(iterator pos);//使用迭代器 map.erase(key);//使用键删除指定范围的元素 map.erase(iterator first, iterator last);//使用迭代器确定边界#include map #include iostream #include stringint main() {std::multimapint, std::string myMultimap;// 插入具有相同键的不同值的元素myMultimap.insert(std::make_pair(1, one));myMultimap.insert(std::make_pair(1, ONE));myMultimap.insert(std::make_pair(2, two));myMultimap.insert(std::make_pair(3, three));myMultimap.insert(std::make_pair(4, four));myMultimap.insert(std::make_pair(5, five));//删除键为2myMultimap.erase(2);//删除键为1的元素myMultimap.erase(myMultimap.find(1));//只能删除one而ONE删不掉//删除键3和键4auto it3myMultimap.find(3);auto it4myMultimap.find(4);myMultimap.erase(it3,it4);for(auto pair:myMultimap){std::coutpair.first:pair.secondstd::endl;}system(pause);return 0; }输出结果 5.提供自定义排序谓词 语法 #include map #include iostream #include string// 自定义比较函数 struct CustomCompare {bool operator()(int a, int b) const {// 基于字符串长度进行比较return std::to_string(a).length() std::to_string(b).length();} };int main() {// 使用自定义比较函数的std::mapstd::mapint, std::string, CustomCompare myMap;// 使用自定义比较函数的std::multimapstd::multimapint, std::string, CustomCompare myMultimap;// 向map中插入元素。由于map中键必须是唯一的这里插入的元素将根据自定义的比较逻辑被排序。myMap.insert({100, Hundred});myMap.insert({10, Ten});myMap.insert({1000, Thousand});// 向multimap中插入元素。multimap允许有相同键的多个元素。myMultimap.insert({100, Hundred});myMultimap.insert({10, Ten});myMultimap.insert({1000, Thousand});myMultimap.insert({100, Another Hundred}); // 允许重复键// 遍历map并打印键值对std::cout Map contents: std::endl;for (const auto pair : myMap) {std::cout pair.first : pair.second std::endl;}// 遍历multimap并打印键值对std::cout Multimap contents: std::endl;for (const auto pair : myMultimap) {std::cout pair.first : pair.second std::endl;}system(pause);return 0; }6.基于散列表的unordered_map和unordered_multimap 从C11起支持散列映射要使用这两个容器需要包含unordered_map有以下特点 因为散列表的特性理想情况下性能更高最坏情况下性能更差无序性 基本操作 #include unordered_map #include iostream #include stringint main() {// 使用整数作为键字符串作为值的unordered_mapstd::unordered_mapint, std::string um;// 插入元素um.insert({1, one});um[2] two; // 使用下标操作符// 查找元素auto it um.find(1);if (it ! um.end()) {std::cout Found: it-second std::endl; // 输出 Found: one} else {std::cout Element with key 1 not found std::endl;}// 删除键为1的元素um.erase(1);// 再次尝试查找键为1的元素it um.find(1);if (it um.end()) {std::cout Element with key 1 not found after erase std::endl;}// 使用整数作为键字符串作为值的unordered_multimapstd::unordered_multimapint, std::string umm;// 插入具有相同键的多个元素umm.insert({1, one});umm.insert({1, ONE});// 查找所有键为1的元素auto range umm.equal_range(1);for (auto it range.first; it ! range.second; it) {std::cout it-second ; // 输出 one ONE}std::cout std::endl;// 删除所有键为1的元素umm.erase(1);// 再次查找键为1的元素应该找不到range umm.equal_range(1);if (std::distance(range.first, range.second) 0) {std::cout No elements with key 1 found after erase std::endl;}system(pause);return 0; }
http://www.hkea.cn/news/14316871/

相关文章:

  • 太原网站建设加q.479185700wordpress 文章打不开
  • 网站建设推广渠道全栈网站开发工程师
  • 做图文的网站西安专业做网站建
  • 公司网站建设制作全包pos机网站报单怎么做
  • php网站后台页面宁波网站免费建设服务平台
  • 河南微网站建设视频网站策划
  • 电商网站界面设计流程制作搜索类网站
  • 设计大师网站网页游戏排行榜前十名网络游戏这you
  • 新网 如何建设网站东营网站建设培训学校
  • 龙口建网站价格免费无网络游戏大全
  • 做手机网站要多少钱广西南宁小程序开发公司
  • 建好了网站怎么做外贸怎样做网站流量统计
  • 维护网站多少钱有没有网站做字体变形
  • 广州做网站推广的公司保险公司销售好做吗
  • 重庆平台网站建设哪里有平面设计素材网站哪个好
  • 商城网站功能介绍公司建设网站需求
  • 化妆品推广软文沈阳seo技术
  • 网站内容被攻击该怎么做设计制作散发寄递销售展示使用
  • 企业网站优化找哪家青海企业网站建设公司
  • 做个网站得花多少钱做网站用什么源码最好
  • 微软网站开发技术常见的网络广告
  • 佛山网站制作做多少钱文库网站建设
  • 网站托管代运营wordpress 自己的数据库
  • asp 网站 模板网站制作工作流程
  • 保定网站维护公司wordpress商家插件
  • 学校网站后台管理源码专注做动漫的门户网站
  • 红色好看的网站冲浪网站优化网
  • 做服务的网站吗企业网站建设的策划书
  • 网站副标题网站排名优化seo
  • 简单个人网站模板广告公司取名大全