#include <vector>
#include <deque>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
class person {
public:
person(string name, int score) {
this->name = name;
this->score = score;
}
string name;
int score;
};
void creat(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()%41 + 60;//使区间在60~100之间
d.push_back(score);
}
cout << it->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;
}
int ave = sum / d.size();
it->score = ave;
}
}
void show(vector<person>& v) {
for (vector<person>::iterator it = v.begin(); it != v.end(); it++) {
cout << it->name << ":" << it->score << endl;
}
}
int main()
{
vector<person>v;//单端数组,记住啊!!!
creat(v);
setscore(v);
show(v);
system("pause");
return 0;
}
c++评委评分
最新推荐文章于 2024-06-18 20:12:34 发布