c++通用算法-count

#include<algorithm>
#include<functional>
#include<iterator>
#include<set>
#include<vector>
#include<iostream>
using namespace std;

template<typename T>
void print(const T& t){
    typename T::const_iterator iter;
    for(iter=t.begin();iter!=t.end();++iter){
        cout << *iter << endl;
    }
}

int main(){
    vector<char> v(5);
    fill(v.begin(),v.end(),'v');
    set<char> cs(v.begin(),v.end());
    typedef set<char>::iterator sci;
    for(sci it=cs.begin();it!=cs.end();++it){
        int n = count(v.begin(),v.end(),*it);//统计有多少个*it(第一个元素)
        cout << *it << ":" << n << ",";
    }
    int lc = count_if(v.begin(),v.end(),bind2nd(greater<char>(),'a'));//统计小写字母个数
    cout << "\nLowercase letters:" << lc << endl;
    sort(v.begin(),v.end());
    print(v);
}

v:5,
Lowercase letters:5
v
v
v
v
v

你可能感兴趣的:(C++,c,算法,C#)