统计vector中重复元素的个数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38228254/article/details/80136015

看代码:

#include <iostream>
#include  <vector>
using namespace std;

int main(){
    vector<int> v;
    v.push_back(3);
    v.push_back(3);
    v.push_back(4);
    // depucate count
    int cnt = count(v.begin(), v.end(), 3);
    cout << "The repeat num=" << cnt << endl;
}

实际上就是对count添加了第三个参数,针对性地查找某一种元素的数量
略略略略略

猜你喜欢

转载自blog.csdn.net/qq_38228254/article/details/80136015