【C++编程基础】AOJ (C++ Programming II)—3-C-count

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值在范围内的出现次数,即计数。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值