#include<iostream>
#include<vector>
#include<deque>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;
//创建5名选手,每位选手各有10个分数
//选手的最终得分为:去掉最高分和最低分之后的平均分
//请给5名选手排名
class Player{
public:
Player(string name,int score):mName(name),mScore(score){
};
Player(){};
public:
string mName;
int mScore;
};
//打印分数函数
void Print_score(deque<int>& d){
for(deque<int>::iterator it=d.begin() ; it!=d.end();it++){
cout<<*it<<" ";
}
}
//选手排序函数
bool Sort_Player(Player p1,Player p2){
return p1.mScore > p2.mScore;
}
//1、创建
void Player_create(vector<Player>& v){
//创建选手ABCDE
string s = "ABCDE";
for(int i=0;i<5;i++){
Player p;
p.mName = "";
p.mName += s[i];
p.mScore = 0;
v.push_back(p);
}
for(vector<Player>::iterator i=v.begin() ; i!=v.end();i++){
cout<<(*i).mName<<" "<<(*i).mScore<<endl;
}
}
//2、打分
void Player_score(vector<Player>& v){
//给5个选手打分数
for(vector<Player>::iterator i=v.begin() ; i!=v.end();i++){
deque<int> d;
for(int j=0;j<10;j++)
d.push_back(rand()%101);
//排序
sort(d.begin(),d.end());
Print_score(d);
cout<<endl;
//去除最高分和最低分
d.pop_back();
d.pop_front();
//计算平均分
int total=0;
for(deque<int>::iterator it=d.begin() ; it!=d.end();it++){
total += *it;
}
int score = total/d.size();
//保存分数
(*i).mScore = score;
}
cout<<endl;
}
//3、排名
void Player_Rank(vector<Player>& v){
sort(v.begin(),v.end(),Sort_Player); //sort第一第二个参数为迭代器,第三个参数为排序条件
cout<<"ID:"<<" "<<"SCORE:"<<endl;
for(vector<Player>::iterator i=v.begin() ; i!=v.end();i++){
cout<<(*i).mName<<" "<<(*i).mScore<<endl;
}
}
int main(){
vector<Player> v;
Player_create(v);
Player_score(v);
Player_Rank(v);
return 0;
}