3-C-count
题目
Count For a given sequence of integers A={a0,a1,…,an−1}, perform the following operations. count(b,e,k): print the number of the specific values k in ab,ab+1,…,ae−1
输入
The input is given in the following format. n a0 a1,…,an−1 q b1 e1 k1 b2 e2 k2 : bq eq kq The number of elements n and each element ai are given in the first line and the second line respectively. In the third line, the number of queries q is given and the following q lines, q integers bi be ki are given as queries.
输出
For each query, print the number of specified values.
样例输入
9
1 4 1 4 2 1 3 5 6
3
0 9 1
1 6 1
3 7 5
样例输出
3
2
0
题解(代码流程)
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, q;
cin >> n;
vector<int> A(n);
for (int i = 0; i < n; i++)cin >> A[i];
cin >> q;
while (q--) {
int b, e, k;
cin >> b >> e >> k;
cout << count(A.begin() + b, A.begin() + e, k) << endl;
}
return 0;
}
小结
运用count(first,end,k)
返回k值在范围内的出现次数,即计数。