#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include<algorithm>
#include <ctime>
using namespace std;
class Person
{
public:
Person(string name, int score)
{
this->m_Name = name;
this->Score = score;
}
string m_Name;
int Score;
};
void creatPerson(vector<Person>& V)
{
string Name_arr = "ABCDE";
for (int i = 0; i < 5; i++)
{
string name;
name = Name_arr[i];
int score = 0;
Person p(name, score);
V.push_back(p);
}
}
void printDetail(const vector<Person>& V) //打印选手信息
{
for (vector<Person>::const_iterator it = V.begin(); it != V.end(); it++)
{
cout << "the name is : " << it->m_Name << " and avg score is : " << it->Score << endl;
}
}
void Get_score(vector<Person>& V) //评委打分
{
srand((unsigned int)time(NULL));
for (vector<Person>::iterator it = V.begin(); it != V.end(); it++)
{
deque<int> d;
for (int i = 0; i <= 9; i++)
{
int score = rand() % 41 + 60;
d.push_back(score);
}
cout << "the name is : " << it->m_Name << " and score is : ";
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;
}
int avg = sum / d.size();
it->Score = avg;
}
}
int main()
{
vector<Person> v;
creatPerson(v);
Get_score(v);
printDetail(v);
return 0;
}
给评委打分(vector,deque容器)
最新推荐文章于 2024-07-12 14:17:28 发布