Problem10581--STL 函数使用 —— count()

10581: STL 函数使用 —— count()

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

【介绍】

【头文件】

Standard Template Library: Algorithms
#include<algorithm>

【作用】

Count appearances of value in range
Returns the number of elements in the range [first,last) that compare equal to val.
The function uses operator== to compare the individual elements to val.
template <class InputIterator, class T>
  typename iterator_traits<InputIterator>::difference_type
    count (InputIterator first, InputIterator last, const T& val);

【任务】

我们通过本题,掌握 count() 函数使用方法。
给一个长度为 $n$ 的数列,找出数列等于某个 val 的数的个数。

Input

第一行包括一个整数 $n\ (1 \leq n \leq 5\times 10^5)$。表示我们有一个长度为 $n$ 的数列。
第二行包括 $n$ 个整数 $a_i\ (-10^9 \leq a_i \leq 10^9)$。
第三行包括一个整数 $m\ (1 \leq n \leq 5\times 10^5)$。表示我们有 $m$ 次循环。
其后 $m$ 行,每行一个整数 $val$,表示询问数列 $a$ 中,数值等于 $val$ 的数量。

Output

对于每一个询问,输出答案。

Sample 1 Input

9
10 20 30 30 20 10 10 20 10
3
10
20
30

Sample 1 Output

3
4
2
有 3 个 10。
有 4 个 20。
有 2 个 30。

Source/Category