如何求一对向量中元素的个数
How to find count of element in a vector of pair
我有一对向量如下
vector<pair<string, vector<string>> v;
我的数据集像
'10', vector1
'10', vector2
'10', vector3
'20', vector4
'20', vector5
我希望输出为count of 10 - 3和count of 20 - 2。我可以知道如何对向量进行计数算法吗?
I tried with
std::count(v.begin(), v.end(), iterator->first)
制作一个简单的直方图:
std::map<std::string, unsigned int> h;
for (auto const & x : v)
{
++h[x.first];
}
for (auto const & p : h)
{
std::cout << p.first << " occurs " << p.second << " times.n";
}
相关文章:
- 将二维数组的所有元素插入到一维数组中
- 求一个数是素数还是素数
- C++ 查找算法:如何找到元素的最后一次出现?
- 我有一系列阵列.可以从一个数组中阅读一些元素和另一个数组中的其他元素
- 将一个数组的每个元素乘以另一个数组的每个元素,并对新的非常大的数组进行排序
- 组合两个数组元素或将一个数组元素分发到另一个数组元素
- C++ 向量元素被最后一次调用push_back替换
- 求一个数组中的数字的和
- 求一棵树的直径
- 初始值设定项列表中元素的求值顺序
- OpenGL:在两个元素之间画一条线
- std::initializer_list和元素的求值顺序
- C++算法优化:从N个元素中求出K组合
- 求一个数组的平均值c++
- 求一个数的排列的gcd
- 求一组数字的GCD
- 求一个数的除数
- 在一个数的特定数字处求一个数
- 求一组子数组的和
- 初始化列表中元素的求值顺序