C++ 向量对的第一个元素的范围

C++ 向量对的第一个元素的范围,c++,C++,我需要找到向量对的第一个元素的范围。我需要一个映射的这个范围,它统计这个向量中的重复条目。 这里是一个代码截取和我如何管理它。也许还有另一个更好的解决方案 unordered_map<int, int> frequency; vector<pair<unsigned int,Point>> Roi_Num_Koord; vector<int> Roi_first_Element; int main() { // Part1: fill t

我需要找到向量对的第一个元素的范围。我需要一个映射的这个范围,它统计这个向量中的重复条目。 这里是一个代码截取和我如何管理它。也许还有另一个更好的解决方案

unordered_map<int, int> frequency;
vector<pair<unsigned int,Point>> Roi_Num_Koord;
vector<int> Roi_first_Element;

int main()
{
    // Part1: fill the Vector pair
    Roi_Num_Koord.emplace_back(make_pair(0,Point(3.6));
    Roi_Num_Koord.emplace_back(make_pair(1,Point(4,8));
    Roi_Num_Koord.emplace_back(make_pair(2,Point(8.3));
    Roi_Num_Koord.emplace_back(make_pair(3,Point(4,6));

    // Part 2: now copy the first element to another vector 

    for (int i = 0; i < Roi_Num_Koord.size(); i++)
    {
        Roi_first_Element.emplace_back(Roi_Num_Koord[i].first);
    }

    // Part 3: now do the duplicate search (Code was taken out of the internet)
    for (int i : Roi_first_Element)
    {
        ++frequency[i];
        cout << "freque "<<frequency[i] << endl;        
    }
    for (const auto& e : frequency)
    {       
        if (e.second == 5)
        {
            std::cout << "Roi " << e.first << " encountered " << e.second << " times\n";
        }
    }
}
无序映射频率;
向量Roi_Num_Koord;
向量Roi_第一_元素;
int main()
{
//第1部分:填充向量对
Roi_Num_Koord.向后放置(形成成对(0,点(3.6));
Roi_Num_Koord.向后放置(形成成对(1,点(4,8));
Roi_Num_Koord.向后放置(形成成对(2,点(8.3));
Roi_Num_Koord.向后放置(形成成对(3,点(4,6));
//第2部分:现在将第一个元素复制到另一个向量
对于(int i=0;icout是的,第二步是完全冗余的。您只需遍历容器,每当您需要对中的第一个元素时,您都会像步骤2中一样显式地说出来

for(const pair<unsigned int,Point>& element : Roi_Num_Koord)
{
    ++frequency[element.first];
    cout << "freque " << frequency[element.first] << endl;        
}
for(常量对和元素:Roi\u Num\u Koord)
{
++频率[元素第一];
库特