practice of STL
Posted doulcl
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了practice of STL相关的知识,希望对你有一定的参考价值。
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");
以上是关于practice of STL的主要内容,如果未能解决你的问题,请参考以下文章
Records of Pytorch in Practice
The Practice of .NET Cross-Platforms
Best Practice of DevOps for Develop Microservice - I
Best Practice of DevOps for Develop Microservice 11 - Cassadra
A Complete Guide to Usage of ‘usermod’ command– 15 Practical Examples with Screenshots
Practical Evaluation of Adversarial Robustness via Adaptive Auto Attack