markdown 计算范围中值的出现次数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 计算范围中值的出现次数相关的知识,希望对你有一定的参考价值。

# include <iostream>
# include <algorithm>
# include <vector>
int main()
{
  std::vector<int> numbers = {1, 2, 3, 5, 6, 3, 4, 1};
  int count = std::count(std::begin(numbers),
                         std::end(numbers),
                         3);
}
**INTENT**

Count the number of occurrences of a particular value in a range of elements.

**DESCRIPTION**
- On line 7, we create a std::vector of int initialized with some values.

- On lines 9–11, we use the alrogithm std::count, to count the occurrences of a particular value in the std::vector. For the first two arguments on lines 9–10, we use std::begin and std::end to get the begin and end iterators for the range in which we wish to count. The third argument on line 11 is the value to count the occurrences of.

- To count elements according to a predicate, you can use std::count_if instead.

以上是关于markdown 计算范围中值的出现次数的主要内容,如果未能解决你的问题,请参考以下文章