首页 > 编程语言 >C++——不存在从 "std::pair<int, int>" 到 "int" 的适当转换函数

C++——不存在从 "std::pair<int, int>" 到 "int" 的适当转换函数

时间:2022-09-30 09:25:46浏览次数:48  
标签:std temp int C++ second key counts row

 1 #include <iostream>
 2 #include <vector>
 3 #include <map>
 4 #include <string>
 5 #include <utility>
 6 
 7 
 8 int Update(std::pair<int, int>a) {
 9     std::pair<int, int> temp;
10 
11     std::vector<int> key_row_1(10);
12     std::vector<int> counts_row_1(10);
13 
14     std::vector<int> key_row_2(10);
15     std::vector<int> counts_row_2(10);
16 
17     std::map<int, int>res_row_1;
18     std::map<int, int>res_row_2;
19     std::map<int, std::map<int,int>>res_sum;
20     std::map<int, int>res;
21 
22 
23     int index1 = (a.first % 2);
24     if(counts_row_1[index1]==0) {
25         key_row_1.insert(key_row_1.begin() + index1, a.first);
26         counts_row_1.insert(counts_row_1.begin() + index1, a.second);
27     } else {
28         temp.first = key_row_1[index1];
29         temp.second = counts_row_1[index1];
30         key_row_1.insert(key_row_1.begin() + index1, a.first);
31         counts_row_1.insert(counts_row_1.begin() + index1, a.second);        
32     }
33 
34 
35 
36     if(temp.second != 0) {
37         int index2 = (temp.first % 2);
38         if(counts_row_2[index2]==0) {
39             key_row_2.insert(key_row_2.begin() + index2, temp.first);
40             counts_row_2.insert(key_row_2.begin() + index2, temp.second);
41         } else {
42             if(temp.second > counts_row_2[index2]) {
43                 key_row_2.insert(key_row_2.begin() + index2, temp.first);
44                 counts_row_2.insert(key_row_2.begin() + index2, temp.second);            
45             } 
46         }
47     }
48 
49     
50     std::cout << "stage1" << std::endl;
51     for(int i=0; i<2; i++) {
52         std::cout << "(" << key_row_1[i] << "," << counts_row_1[i] << ")" << "; ";
53         res_row_1.insert(std::pair<int,int>(key_row_1[i], counts_row_1[i]));
54     }
55     std::cout << std::endl;
56     std::cout << "stage2" << std::endl;
57     for(int i=0; i<2; i++) {
58         std::cout << "(" << key_row_2[i] << "," << counts_row_2[i] << ")" << "; ";
59         res_row_2.insert(std::pair<int,int>(key_row_1[i], counts_row_1[i]));
60     }
61     std::cout << std::endl;
62 
63     
64     std::cout << "the final result as follow: " << std::endl;
65 
66     res_sum.insert({1,res_row_1});
67     res_sum.insert({2,res_row_2});
68 
69     auto iter = res_sum.begin();
70     for(; iter != res_sum.end(); ++iter) {
71         res.insert(iter->second.begin(), iter->second.end());
72     }
73 
74     for(const auto &i : res) {
75         std::cout << i.first << ":" << i.second << "; ";
76     }
77     std::cout << '\n';
78 
79 }
80 
81 
82 int main(int argc, char* agrv[]) {
83     std::vector<std::pair<int, int> >p;
84     p.push_back(std::make_pair(1,5));
85     p.push_back(std::make_pair(2,6));
86     p.push_back(std::make_pair(3,7));
87     p.push_back(std::make_pair(4,8));
88     p.push_back(std::make_pair(5,9));
89 
90     for(int i=0; i<5; i++) {
91         int Update(p[i]);
92     }  
93 }

  在主函数中调用Update函数时,出现如下错误:

  

  有待后续解决!!!

    

 

标签:std,temp,int,C++,second,key,counts,row
From: https://www.cnblogs.com/hjxiamen/p/16743765.html

相关文章

  • 利用C++语言实现“完数”的输出(键入范围)
    ​目录文章目录前言一、“完数”是什么?二、代码直入1.键盘键入所求输出范围的实现2.完整代码总结    前言 利用C++语言实现“完数”的输出 一......
  • Effective Modern C++ 英文版 pdf
    高清扫描版下载链接:https://pan.baidu.com/s/15aAzcL50G7kNPPEVEDfKhQ点击这里获取提取码 ......
  • C++调用python(二)
    目录三、调用函数四、调用类五、调用SSD目标检测算法六、遇到的错误参考链接:正文一、基本使用方法二、调用简单语句三、调用函数四、调用类五、调用SSD目标......
  • C++指针入门
    C++指针入门目录C++指针入门C++中变量位置C++中指针的声明利用指针实现swap()C++中变量位置#include<iostream>usingnamespacestd;intmain(){intvar1;......
  • 如何在Intellij IDEA运行和调试JavaScript
    浏览器都可以解析和运行JS,但最好的方式应该还是使用node.js来运行。所以第一步就是安装node。对于Mac,一条命令即可:$brewinstallnode安装完成后,可以检查一下对应的......
  • 浅析 C++ 调用 Python 模块
    浅析C++调用Python模块作为一种胶水语言,Python能够很容易地调用C、C++等语言,也能够通过其他语言调用Python的模块。Python提供了C++库,使得开发者能很方便......
  • C++ CMake 使用 Python3
    C++CMake使用Python3CMakeListst设置#如果使用的是非系统目录下的Python可以通过指定Python3_ROOT_DIR改变查找路径#set(Python3_ROOT_DIR"${CMAKE_SOURCE_D......
  • C++ 调用python方法
    主流方法将python程序编程文本形式的动态链接库,在c/c++程序中调用其中定义的函数。本质上是在c++中启动了一个python解释器,由解释器对python相关的代码进行执行,执行......
  • flutter系列之:深入理解布局的基础constraints
    目录简介Tight和looseconstraints理解constraints的原则总结简介我们在flutter中使用layout的时候需要经常对组件进行一些大小的限制,这种限制就叫做constraints,用来控制......
  • Microsoft PowerPoint LTSC 2021 for Mac(ppt演示工具)v16.67 beta版 mac/win
    PowerPoint2021forMac是一款能够在mac平台上使用的ppt演示工具,随时随地快速轻松地创建、编辑、查看、演示或共享演示文稿。需要随时随地快速访问最近使用的PowerPoint......