案例描述
- 有五名选手, ABCDE, 10个评委分别对每一名选手打分, 去除最高分和最低分后取平均分
实现步骤
- 把五名选手放入一个vector容器
- 遍历vector容器, 取出每一名选手, 执行for循环, 把十个得分放入deque容器中
- sort算法对deque中分数进行排序, 去除最高分和最低分
- deque遍历一遍, 类加分数
- 获取平均分
代码实现
Person.hpp
#ifndef Person_hpp
#define Person_hpp
#include <iostream>
#include <deque>
#include <string>
using namespace std;
class Person
{
public:
Person(string name, deque<int>& score)
{
this->score = score;
this->name = name;
}
deque<int> score;
string name;
};
#endif
main.cpp
#include <iostream>
#include <vector>
#include <algorithm>