#include<iostream>
using namespace std;
#include<deque>
#include<algorithm>
#include<vector>
#include<string>
class person
{
public:
person(string Name, int Score)
{
name = Name;
score = Score;
}
string name; // 人名
int score; //分数
};
void createPerson(vector<person>&v)
{
string nameSeed = "ABCDE";
for (int i = 0; i < 5; i++)
{
string name = "选手";
name += nameSeed[i];
int score = 0;
person p(name, score);
v.push_back(p);
}
}
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++)
{
int score = rand() % 40 + 60; //60~99
d.push_back(score);
}
//先看下打分
/* for (deque<int>::iterator d1 = d.begin(); d1 != d.end(); d1++)
{
cout << *d1 << " ";
}
cout << endl;*/
//排序
sort(d.begin(), d.end());
//取出最高和最低
d.pop_front();
d.pop_back();
int sum = 0;
for (deque<int>::iterator d1 = d.begin(); d1 != d.end(); d1++)
{
sum += *d1;
}
int avg = sum / d.size();
it->score = avg;
}
}
void showScore(vector<person>&v)
{
for (vector<person>::iterator it = v.begin(); it != v.end(); it++)
{
cout << "姓名:" << it->name << "年龄" << it->score << endl;
}
}
int main()
{
//创建容器,存w放选手.
vector<person> v;
//创建五名选手
createPerson(v);
//打分
setScore(v);
//展示平均分
showScore(v);
system("pause");
return 0;
}
三大容器实现评委打分
最新推荐文章于 2024-04-26 01:45:18 发布