【发布时间】:2018-06-13 15:49:35
【问题描述】:
我需要找到向量对的第一个元素的范围。我需要这个范围作为地图,它计算这个向量中的重复条目。 这是一个代码片段以及我如何管理它。也许还有其他更好的解决方案?
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";
}
}
}
那么有没有可能删除第2部分并找出Roi_Num_Koord的第一个元素的范围?这样我就不必将此向量的第一个元素复制到另一个向量(Roi_first_Element )
【问题讨论】:
标签: c++