#include<iostream>
using namespace std;
#include<vector>
#include<deque>
#include<algorithm>
class Person
{
public:
Person(string name,int score)
{
this->m_Name = name;
this->m_Score = score;
}
string m_Name;
int m_Score;
};
//创建五名选手
void createPerson(vector<Person>& v)
{
string name = "选手";
string nameSeed = "ABCDE";
for (int i = 0; i < 5; i++)
{
name += nameSeed[i];
v.push_back(Person(name, 0));
}
}
//给选手打分
void setScore(vector<Person>& v)
{
for (vector<Person>::iterator it = v.begin(); it != v.end(); it++)
{
deque<int>d;
for (int i = 0; i < 10; i++)
{
d.push_back(rand()%41 + 60);
}
cout << it->m_Name << "具体得分为: " << endl;
for (deque<int>::iterator dit = d.begin(); dit != d.end(); dit++)
{
cout << *dit << " ";
}
cout << endl;
sort(d.begin(),d.end());
d.pop_back();
d.pop_front();
//计算平均分
int sum = 0;
for (deque<int>::iterator dit = d.begin(); dit != d.end(); dit++)
{
sum+=*dit;
}
it->m_Score = sum / d.size();
cout << "其最终平均分为: " << it->m_Score << endl << endl;
}
}
void test01()
{
vector<Person> v;
createPerson(v);
setScore(v);
}
int main() {
test01();
}
结果:
标签:name,STL,++,int,Score,dit,评委,include,打分 From: https://blog.csdn.net/weixin_47768406/article/details/141488158