标签:set deque sort str art clu blog size class
from https://blog.csdn.net/zzyczzyc/article/details/82935467
#include<algorithm>
#include<deque>
class player
{
public:
player(string name,int score):mName(name),mScore(score){};
~player(){};
string getname(void) {return mName;}
int getplayerScore(void) {return mScore;}
void setScore(int score) {mScore = score;}
private:
string mName;
int mScore;
};
void setplayer(vector<player> & group)
{
string a = "ABCDE";
for(int i = 0; i < int(a.length());i++)
{
string name = string("player")+a[i];
player p(name,0);
group.push_back(p);
}
}
bool compare(player & p1,player & p2)
{
return (p1.getplayerScore() >= p2.getplayerScore());
}
void getscore(vector<player> & mgroup)
{
for(int k = 0;k <int(mgroup.size());k++)
{
deque<int> scorelist;
for(int i = 0; i < 10 ; i++)
{
int temp = rand()%100;
scorelist.push_back(temp);
}
sort(scorelist.begin(),scorelist.end());
scorelist.pop_back();
scorelist.pop_front();
int total = 0;
deque<int>::iterator it = scorelist.begin();
for(;it != scorelist.end();it++)
{
total += *it;
}
mgroup[k].setScore(total/(scorelist.size()));
cout<<mgroup[k].getname()<<" score:"<<mgroup[k].getplayerScore()<<endl;
}
sort(mgroup.begin(),mgroup.end(),compare);
cout << "after sort!"<<endl;
for(int k = 0;k <int(mgroup.size());k++)
{
cout<<mgroup[k].getname()<<" score:"<<mgroup[k].getplayerScore()<<endl;
}
}
void main()
{
vector<player> group;
setplayer(group);
getscore(group);
system("pause");
}
标签:set deque sort str art clu blog size class
原文地址:https://www.cnblogs.com/doulcl/p/10979102.html