演讲管理打分系统vector deque容器

利用vector和deque容器设计的演讲管理打分系统

利用rand函数为各位选手打分

#include<iostream>
#include<string>
#include<vector>
#include<deque>
#include <algorithm>
#include<ctime>
using namespace std;
class Person {
public:
	Person(string name,double score)
	{
		this->m_Name = name;
		this->m_Score = score;
	}
public:
	string m_Name;
	double m_Score;
};
double getScore()
{
	deque<double>Judges(10);
	for (int i = 0; i < Judges.size(); i++)
	{
		Judges.at(i) = rand() % 41 + 60;
	}
	sort(Judges.begin(), Judges.end());
	Judges.pop_back();
	Judges.pop_front();
	double sumScore = 0;
	for (int i = 0; i < Judges.size(); i++)
	{
		sumScore += Judges.at(i);
	}
	return sumScore / 8;
}
bool complare(Person a,Person b)
{
	return a.m_Score>b.m_Score;
}
int main()
{
	vector<Person>player;
	Person player1("孙悟空",0);
	Person player2("刘备",0);
	Person player3("孙权",0);
	Person player4("林黛玉",0);
	Person player5("林冲",0);
	player.push_back(player1);
	player.push_back(player2);
	player.push_back(player3);
	player.push_back(player4);
	player.push_back(player5);
	srand((unsigned int)time(NULL));
	for (int i = 0; i < player.size(); i++)
	{
		player.at(i).m_Score = getScore();
	}
	sort(player.begin(),player.end(),complare );
	for (vector<Person>::iterator it = player.begin(); it != player.end(); it++)
	{
		cout << "Name: " << (*it).m_Name << "   Score:"<<(*it).m_Score<<endl;
	}
	cout << "第一名是: " << player.at(0).m_Name << "  得分:" << player.at(0).m_Score << endl;
	cout << "第二名是: " << player.at(1).m_Name << "  得分:" << player.at(1).m_Score << endl;
	cout << "第三名是: " << player.at(2).m_Name << "  得分:" << player.at(2).m_Score << endl;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值