STL练习程序(vector...)

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
using namespace std;
int testscore[] = {67, 56, 24, 78, 99, 87, 56};

bool pass(int n)
{
if (n>=60)
return true;
else
return false;
}

void main()
{
vector<int> score(testscore,testscore+sizeof(testscore)/sizeof(int));
vector<int>::iterator it;

for (it=score.begin();it!=score.end();it++)
{
cout<<*it<<"";
}
cout<<endl;

sort(score.begin(),score.end());

for (it=score.begin();it!=score.end();it++)
{
cout<<*it<<"";
}
cout<<endl;

it=max_element(score.begin(),score.end());
cout<<"max is:"<<*it<<endl;

it=min_element(score.begin(),score.end());
cout<<"min is:"<<*it<<endl;

for (it=score.begin();it!=score.end();it++)
{
if(!pass(*it))
{
cout<<*it<<endl;
}
}

cout<<"the number of pass people:"<<count_if(score.begin(),score.end(),pass)<<endl;
int total=accumulate(score.begin(),score.end(),0);
cout<<total<<endl;

}
posted @ 2012-02-07 21:27  Dsp Tian  阅读(791)  评论(0编辑  收藏  举报