#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <ctime>
#include <string>
using namespace std
;
class Person
{
public:
Person(string name
, double score
)
{
m_name
= name
;
m_score
= score
;
}
string m_name
;
double m_score
;
};
void createPerson(vector
<Person
>& v
)
{
string nameSeed
= "ABCDE";
for (int i
= 0; i
< nameSeed
.size(); i
++)
{
string str
= "选手";
str
+= nameSeed
[i
];
Person
p(str
, 0);
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_back();
d
.pop_front();
double sum
= 0;
for (deque
<int>::iterator dit
= d
.begin(); dit
!= d
.end(); ++dit
)
{
sum
+= *dit
;
}
sum
/= d
.size();
it
->m_score
= sum
;
}
}
class Print
{
public:
void operator()(Person
& p
)const
{
cout
<< "姓名:" << p
.m_name
<< " 平均分:" << p
.m_score
<< endl
;
}
};
void print(Person
& p
)
{
cout
<< "姓名: " << p
.m_name
<< " 平均分" << p
.m_score
<< endl
;
}
void showScore(vector
<Person
>& v
)
{
for_each(v
.begin(), v
.end(), print
);
}
int main()
{
srand((unsigned int)time(NULL));
vector
<Person
>v
;
createPerson(v
);
setScore(v
);
showScore(v
);
return 0;
}
C++STL案例-评委打分
转载请注明原文地址:https://tech.qufami.com/read-27141.html