#include <iostream>     // cout
#include <algorithm>    // count
#include <vector>       // vector
using namespace std;
int main () {
    // counting elements in array:
    int myints[] = {10,20,30,30,20,10,10,20};   // 8 elements
    int mycount = count(myints, myints+6, 10);
    cout << "10 appears " << mycount << " times.\n";
    
    // counting elements in container:
    vector<int> myvector (myints, myints+8);
    mycount = count(myvector.begin()+2, myvector.end(), 20);
    cout << "20 appears " << mycount  << " times.\n";
    
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-11-22
  • 2021-07-14
  • 2021-12-28
  • 2022-12-23
  • 2021-07-05
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-01
  • 2021-07-01
  • 2022-12-23
相关资源
相似解决方案