#include <iostream>
#include <vector>
#include <deque>
#include <string>
#include <algorithm>
#include <ctime>
using namespace std;
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) {
for (int i = 0; i < 5; i++) {
string name = "选手";
name += 'A' + 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() % 41 + 60;
d.push_back(score);
}
sort(d.begin(), d.end());
//去除最高最低分
d.pop_front();
d.pop_back();
//取平均分
int sum = 0;
for (deque<int>::iterator ip = d.begin(); ip != d.end(); ip++) {
sum += *ip;
}
sum = sum / d.size();
it->M_score = sum;
}
}
void ShowScore(vector<Person>& v) {
for (vector<Person>::iterator it = v.begin(); it != v.end(); it++) {
cout << it->M_name << " " << it->M_score << endl;
}
}
int main() {
//随机数种子
srand((unsigned int)time(NULL));
//创建五位选手
vector<Person>v;
CreatePerson(v);
//给五位选手打分
SetScore(v);
//显示最后得分
ShowScore(v);
system("pause");
return 0;
}
黑马程序员——评委打分
最新推荐文章于 2022-10-11 18:31:18 发布