#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int student_Score[] = { 50,80,93,23,66};
void pritit(int nScore)
{
cout<<nScore<<" ";
}
bool unPass(int nScore)
{
return nScore < 60;
}
bool Pass(int nScore)
{
return nScore >= 60;
}
int main(int argc, char* argv[])
{
vector<int> v_score(student_Score,student_Score+sizeof(student_Score)/sizeof(int));
vector<int>::iterator index;
//排序
sort(v_score.begin(),v_score.end());
//显示
for_each(v_score.begin(),v_score.end(),pritit); cout<<endl;
//显示最小
index = min_element(v_score.begin(),v_score.end());
cout<<"最小分数 "<<*index<<endl;
//显示最大
index = max_element(v_score.begin(),v_score.end());
cout<<"最大分数 "<<*index<<endl;
//显示不低于60分的数量
cout<<"低于60的数量 " <<count_if(v_score.begin(),v_score.end(),unPass)<<endl;
//高于60的数量
cout<<"高于60的数量 "<<count_if(v_score.begin(),v_score.end(),Pass)<<endl;
//平均数
int sum = 0;
for (index = v_score.begin(); index != v_score.end(); index++)
{
sum += *index;
}
cout<<"平均数 "<<sum / v_score.size() <<endl;
return 0;
}
algorithm 简单用法
最新推荐文章于 2023-08-31 12:05:36 发布