~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
开发工具与关键技术:vs2015,C++STL
作者:
撰写时间:19年7月7日
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<numeric>
#include<deque>
#include<time.h>
#include<functional>
using namespace std;
class player
{
public:
string name;
int Score[3];
};
void CreatePlayer(map<int, player>&plays,vector<int>&v1)//创建选手
{
stringNo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(int i = 0; i < 24; i++)
{
playerp;
p.name= "选手";
p.name+= No[i];
plays.insert(pair<int,player>(1 + i, p));
v1.push_back(1+ i);
}
}
void disorganize(vector<int>&v)//打乱选手
{
cout<< "----------晋级赛待审----------"<< endl;
random_shuffle(v.begin(),v.end());
}
void game(int index,map<int, player>&plays,vector<int>&AInput, vector<int>&AOut)//比赛
{
multimap<int,int, greater<int>>TempScore;
intcouts = 0;
for(vector<int>::iterator it = AInput.begin(); it != AInput.end();++it)
{
couts++;
deque<int>score;
for(int i = 0; i < 10; i++)
{
score.push_back(rand()% 40 + 60);
}
sort(score.begin(),score.end());
score.pop_front();
score.pop_back();
intSumscore = accumulate(score.begin(), score.end(), 0);
intAvg = Sumscore / score.size();
plays[*it].Score[index-1]=Avg;
TempScore.insert(pair<int,int>(Avg, *it));
if(couts%6==0)
{
cout<< "小组的比赛成绩" << endl;
for(multimap<int, int, greater<int>>::iterator it = TempScore.begin();it != TempScore.end();++it)
{
//编号 姓名 得分
cout<< "参赛编号: "<< (*it).second <<"\t"<<plays[(*it).second].name << "\t" << (*it).first <<endl;
}
while(TempScore.size()>3)
{
multimap<int, int, greater<int>>::iteratolit=TempScore.begin();
AOut.push_back(lit->second);
TempScore.erase(lit);
}
cout << endl;
TempScore.clear();
}
}
}
voidgameresult(int index,map<int, player>&plays,vector<int>&AOut)//打印比赛结果
{
cout << "第" << index <<"轮" <<" "<<"晋级名单" << endl;
for (vector<int>::iteratorit = AOut.begin(); it != AOut.end();++it)
{
//编号 姓名 得分
cout<< "参赛编号: " << *it << "\t"<< plays[*it].name << "\t" << plays[*it].Score[index-1]<< endl;
}
}
void main()
{
srand(time(0));
map<int,player>plays;
vector<int>v1;
vector<int>v2;
vector<int>v3;
vector<int>v4;
CreatePlayer(plays,v1);
//第一轮
disorganize(v1);
game(1,plays,v1,v2);
gameresult(1,plays,v2);
cout<< endl;
//第二轮
disorganize(v2);
game(2,plays, v2, v3);
gameresult(2,plays, v3);
cout<< endl;
//第三轮
disorganize(v3);
game(3,plays, v3, v4);
gameresult(3,plays, v4);
}
运行结果:
开发工具与关键技术:vs2015,C++STL
作者:
撰写时间:19年7月7日
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<numeric>
#include<deque>
#include<time.h>
#include<functional>
using namespace std;
class player
{
public:
string name;
int Score[3];
};
void CreatePlayer(map<int, player>&plays,vector<int>&v1)//创建选手
{
stringNo = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(int i = 0; i < 24; i++)
{
playerp;
p.name= "选手";
p.name+= No[i];
plays.insert(pair<int,player>(1 + i, p));
v1.push_back(1+ i);
}
}
void disorganize(vector<int>&v)//打乱选手
{
cout<< "----------晋级赛待审----------"<< endl;
random_shuffle(v.begin(),v.end());
}
void game(int index,map<int, player>&plays,vector<int>&AInput, vector<int>&AOut)//比赛
{
multimap<int,int, greater<int>>TempScore;
intcouts = 0;
for(vector<int>::iterator it = AInput.begin(); it != AInput.end();++it)
{
couts++;
deque<int>score;
for(int i = 0; i < 10; i++)
{
score.push_back(rand()% 40 + 60);
}
sort(score.begin(),score.end());
score.pop_front();
score.pop_back();
intSumscore = accumulate(score.begin(), score.end(), 0);
intAvg = Sumscore / score.size();
plays[*it].Score[index-1]=Avg;
TempScore.insert(pair<int,int>(Avg, *it));
if(couts%6==0)
{
cout<< "小组的比赛成绩" << endl;
for(multimap<int, int, greater<int>>::iterator it = TempScore.begin();it != TempScore.end();++it)
{
//编号 姓名 得分
cout<< "参赛编号: "<< (*it).second <<"\t"<<plays[(*it).second].name << "\t" << (*it).first <<endl;
}
while(TempScore.size()>3)
{
multimap<int, int, greater<int>>::iteratolit=TempScore.begin();
AOut.push_back(lit->second);
TempScore.erase(lit);
}
cout << endl;
TempScore.clear();
}
}
}
voidgameresult(int index,map<int, player>&plays,vector<int>&AOut)//打印比赛结果
{
cout << "第" << index <<"轮" <<" "<<"晋级名单" << endl;
for (vector<int>::iteratorit = AOut.begin(); it != AOut.end();++it)
{
//编号 姓名 得分
cout<< "参赛编号: " << *it << "\t"<< plays[*it].name << "\t" << plays[*it].Score[index-1]<< endl;
}
}
void main()
{
srand(time(0));
map<int,player>plays;
vector<int>v1;
vector<int>v2;
vector<int>v3;
vector<int>v4;
CreatePlayer(plays,v1);
//第一轮
disorganize(v1);
game(1,plays,v1,v2);
gameresult(1,plays,v2);
cout<< endl;
//第二轮
disorganize(v2);
game(2,plays, v2, v3);
gameresult(2,plays, v3);
cout<< endl;
//第三轮
disorganize(v3);
game(3,plays, v3, v4);
gameresult(3,plays, v4);
}
运行结果: