3.4 案例-评委打分

3.4 案例-评委打分

3.4.1 案例描述

有5名选手: 选手ABCDE,10个评委分别对每一名选手打分,去除最高分,去除评委中最低分,取平均分

3.4.2 实现步骤

  1. 创建五名选手,放到vector中
  2. 遍历vector容器,取出来每一个选手,执行for循环,可以把10个评分打分存到deque容器中
  3. sort算法对deque容器中分数排序,去除最高和最低分
  4. deque容器遍历一遍,累加总分
  5. 获取平均分
#include <iostream>
#include<vector>
#include<algorithm>//标准算法的头文件
#include<string>
#include<deque>
#include<ctime>
using namespace std;
class Xuanshou
{
public:
	Xuanshou(string name, int score)
	{
		this->m_name = name;
		this->m_score = score;

	}
	string m_name;
	int m_score;
};

void Create_5_Xuanshou(vector<Xuanshou>&v)
{
	string str = "ABCDE";

	for (int i = 0; i < 5; i++)
	{
		string str2 = "选手";
		str2 += str[i];
		int score = 0;
		Xuanshou xuan(str2, score);
		v.push_back(xuan);
	}
}

void Dafen(vector<Xuanshou> &v)
{
	for (vector<Xuanshou>::iterator it = v.begin(); it != v.end(); it++)
	{
		//cout << (*it).m_name << " " << (*it).m_score << endl;
		deque<int> d;
		cout <<"对"<< (*it).m_name << "打分!" << endl;
		for (int j = 0; j < 10; j++)
		{
			cout << "评委"<<j+1<<"打分!" << endl;
			int setScore = rand() % 41 + 60;//60~100分
			d.push_back(setScore);
		}
		sort(d.begin(), d.end());
		d.pop_back();
		d.pop_front();
		int sum = 0;
		/*
		for (int i = 0; i < d.size(); i++)
		{
			sum += d.at(i);
		}
		*/
		for (deque<int>::iterator it = d.begin(); it != d.end(); it++)
		{
			sum += (*it);
		}
		int avg = sum / d.size();
		it->m_score = avg;
	}
}
int main()
{
	srand((unsigned int)time(NULL));
	//test();
	//test02();
	//test03();
	//test04();
	//test05();
	//test000();
	//test001();
	//test002();
	vector<Xuanshou> v;
	Create_5_Xuanshou(v);
	Dafen(v);
	for (vector<Xuanshou>::iterator it = v.begin(); it != v.end(); it++)
	{
		cout << (*it).m_name << " " << (*it).m_score << endl;
	}
    std::cout << "Hello World!\n"; 
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

colorful_stars

您是我见过全宇宙最可爱的人!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值