演讲比赛流程管理系统
演讲比赛程序需求
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0008b742091283c096a308a069d55ac1.png#pic_center)
程序功能
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/6a58dc0a2064bfeb75e7a86751ed22da.png#pic_center)
代码实现
#include <iostream>
using namespace std;
#include <cstring>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <functional>
#include <iterator>
#include<numeric>
#include <map>
#include <deque>
using namespace std;
class Speaker{
public:
string speaker;
int score[3];
};
void CreatSpeaker(map<int, Speaker> &mspeaker, vector<int> &v)
{
string name = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
Speaker tmp;
for(int i = 0; i < 24; i++){
tmp.speaker = "选手";
tmp.speaker = tmp.speaker + name[i];
mspeaker.insert(pair<int, Speaker>(i+100, tmp));
}
for(int i = 0; i < 24; i++){
v.push_back(i+100);
}
}
void speech_contest_draw(vector<int> &v)
{
random_shuffle(v.begin(), v.end());
}
void speech_contest(int index, map<int, Speaker> &mspeaker, vector<int> &v1, vector<int> &v2)
{
multimap<int, int, greater<int>> multimapGroup;
int count = 0;
for(vector<int>::iterator v_it = v1.begin(); v_it != v1.end(); v_it++){
count++;
deque<int> dscore;
for(int i = 0; i < 10; i++){
dscore.push_back(50 + rand()%50);
}
sort(dscore.begin(), dscore.end());
dscore.pop_front();
dscore.pop_back();
int sum_score = 0;
for(deque<int>::const_iterator d_it = dscore.begin(); d_it != dscore.end(); d_it++)
{
sum_score += (*d_it);
}
int ave_score = sum_score / dscore.size();
mspeaker[*v_it].score[index] = ave_score;
multimapGroup.insert(pair<int, int>(ave_score, *v_it));
if(count % 6 == 0)
{
cout << "-------------------- 小组比赛成绩 ----------------------" << endl;
cout << "序号" << "\t姓名" << "\t得分" << endl;
for(multimap<int, int, greater<int>>::iterator mul_it = multimapGroup.begin(); mul_it != multimapGroup.end(); mul_it++){
cout << mul_it->second << "\t" << mspeaker[mul_it->second].speaker << "\t" << mul_it->first << endl; //mspeaker[mul->second].score[index] <=> mul->first; 仅次于在该循环中
}
while(multimapGroup.size() > 3){
multimap<int, int, greater<int>>::iterator mul_it = multimapGroup.begin();
v2.push_back(mul_it->second);
multimapGroup.erase(mul_it);
}
multimapGroup.clear();
}
}
}
void speech_contest_print(int index, map<int, Speaker> &mspeaker, vector<int> &v)
{
cout << "-------------- 晋级名单 ---------------" << endl;
cout << "序号" << "\t姓名" << "\t得分" << endl;
for(vector<int>::iterator v_it = v.begin(); v_it != v.end(); v_it++){
cout << *v_it << "\t" << mspeaker[*v_it].speaker << "\t" << mspeaker[*v_it].score[index] << endl;
}
}
int main()
{
map<int, Speaker> mspeaker;
vector<int> v1; //选手人员名单
vector<int> v2;
vector<int> v3;
vector<int> v4;
CreatSpeaker(mspeaker, v1);
cout << "\n\n\n任意键,开始第一轮比赛" << endl;
cin.get();
speech_contest_draw(v1);
speech_contest(0, mspeaker, v1, v2);
speech_contest_print(0, mspeaker, v2);
cout << "\n\n\n任意键,开始第二轮比赛" << endl;
cin.get();
speech_contest_draw(v1);
speech_contest(1, mspeaker, v2, v3);
speech_contest_print(1, mspeaker, v3);
cout << "\n\n\n任意键,开始第三轮比赛" << endl;
cin.get();
speech_contest_draw(v1);
speech_contest(2, mspeaker, v3, v4);
cout<< "\n\n\n最终决赛获胜人员" << endl;
speech_contest_print(2, mspeaker, v4);
system("pause");
}