当前位置: 首页 > wzjs >正文

做首页网站成品云计算培训

做首页网站成品,云计算培训,wordpress拒绝服务,godaddy空间建立wordpress需求 分析 1、初始化&#xff0c;生成演讲学生数组&#xff0c;打乱数组以便随机分组 2、每轮比赛后需要统计每个学生的胜场&#xff0c;以便决定进入下一轮和最终胜利的学生 代码实现 #pragma once#include<iostream> #include<string> #include<algorithm…

需求

分析

1、初始化,生成演讲学生数组,打乱数组以便随机分组

2、每轮比赛后需要统计每个学生的胜场,以便决定进入下一轮和最终胜利的学生

代码实现

#pragma once#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>using namespace std;/*
* N为M的倍数
* N(=12)个学生参加演讲比赛。比赛共两轮。
* 第一轮、分组淘汰赛,随机分组,每组M(=6)人,两两演讲PK。每组决出前三名进入下一轮。
* 第二轮、决赛,每组两两PK,决出比赛前三名。
* 每轮比赛过后显示晋级选手信息。(可以保存比赛记录到文件中,方便查看)
*/
class Student {
public:int id;string name;Student(int id, string name) : id(id), name(name) {this->id = id;this->name = name;}int say() { // 演讲 通过比较随机数大小判断演讲胜负return rand() % 12;}
};static const int NUM = 12;
static const int MAX_NUM = 10001;
static Student** stu;
static Student** origin_stu;
static string s_name = "ABCDEFGHIJKL";auto int_asc_sort = [](int a, int b)->bool {return a > b;
};
auto asc_sort = [](pair<Student*, int> a, pair<Student*, int> b)->bool {return a.second > b.second;
};
static void print_set_no_erase(multiset<pair<Student*, int>, decltype(asc_sort)> topK) {for (multiset<pair<Student*, int>, decltype(asc_sort)>::iterator a = topK.begin(); a != topK.end(); a++) {pair<Student*, int> p = *a;Student* s = p.first;int count = p.second;cout << "id:" << s->id << " name:" << s->name << " 胜场: " << count << endl;}
}
static multiset<pair<Student*, int>, decltype(asc_sort)> print_set(multiset<pair<Student*, int>, decltype(asc_sort)> topK) {cout << "胜场降序排序后......" << endl;int limit = 1;for (multiset<pair<Student*, int>, decltype(asc_sort)>::iterator a = topK.begin(); a != topK.end(); a++) {if (limit++ > 6) {break;}pair<Student*, int> p = *a;Student* s = p.first;int count = p.second;cout << "id:" << s->id << " name:" << s->name << " 胜场: " << count << endl;}multiset<pair<Student*, int>, decltype(asc_sort)>::iterator a = topK.begin();a++; a++; a++;topK.erase(a, topK.end());return topK;
}
static void print_score(int a[], int len) {for (int i = 0; i < len; i++) {cout << s_name.substr(i, 1) << " 胜场: " << a[i] << endl;}
}
static multiset<pair<Student*, int>, decltype(asc_sort)> print_score(int a[], int len, multiset<pair<Student*, int>, decltype(asc_sort)> topK) {for (int i = 0; i < len; i++) {//cout << s_name.substr(i, 1) << " stu[" << i << "] = " << a[i] << endl;topK.insert(make_pair(origin_stu[i], a[i]));}return print_set(topK);
}
static void print_stu(Student ** stu, int len) {for (int i = 0; i < len; i++) {cout << "student[" << i << "] id:" << stu[i]->id << " name:" << stu[i]->name << endl;}
}// 初始化演讲的学生,打乱顺序以便随机分组
void init() {stu = new Student* [NUM];origin_stu = new Student* [NUM];srand(time(NULL));for (int i = 0; i < NUM; i++) {stu[i] = new Student(10000 + i + 1, s_name.substr(i, 1));origin_stu[i] = new Student(10000 + i + 1, s_name.substr(i, 1));}random_shuffle(stu, stu+NUM);//print_stu(stu);
}void competition(Student** stu1, Student** stu2, int len, int result[], int result2[]) {for (int i = 0; i < len; i++) {for (int j = 0; j < len; j++) {cout << "比赛:" << stu1[i]->name << " PK " << stu2[j]->name << " ";if (stu1[i]->say() >= stu2[j]->say()) {cout << stu1[i]->name << "胜" << endl;result[stu1[i]->id - MAX_NUM]++;}else{cout << stu2[j]->name << "胜" << endl;result2[stu2[j]->id - MAX_NUM]++;}}}
}// 提取哪些学生晋级了
void extraction(multiset<pair<Student*, int>, decltype(asc_sort)> top, Student** s) {int i = 0;for (multiset<pair<Student*, int>, decltype(asc_sort)>::iterator a = top.begin(); a != top.end(); a++) {s[i++] = a->first;}
}void merge_array(int a[], int b[], int c[], int len) {for (int i = 0; i < len; i++) {c[i] = a[i] + b[i];}
}void main_entry() {init();cout << "输入1开始第一轮比赛:";int start1;cin >> start1;if (start1 != 1) {cout << "游戏中止......" << endl;return;}Student** stu1 = new Student* [NUM/2];Student** stu2 = new Student * [NUM / 2];for (int i = 0; i < NUM; i++) {if (i < NUM/2) {stu1[i] = stu[i];}else {stu2[i-NUM/2] = stu[i];}}cout << "第一轮分组情况:" << endl;cout << "1组: " << endl;print_stu(stu1, NUM/2);cout << "2组: " << endl;print_stu(stu2, NUM / 2);delete[] stu;srand(time(NULL));int result[NUM] = {0};int result2[NUM] = {0};// 总共36场比赛 6 * 6 = 36// 0 7 8 9 10 11 12// 1 7 8 9 10 11 12// 2 7 8 9 10 11 12// 3 7 8 9 10 11 12// 4 7 8 9 10 11 12// 5 7 8 9 10 11 12// 6 7 8 9 10 11 12cout << "第一轮总共36场比赛,比赛结果如下:" << endl;competition(stu1, stu2, NUM/2, result, result2);//for (int i = 0; i < NUM / 2; i++) {//	for (int j = 0; j < NUM / 2; j++) {//		if (stu1[i]->say() >= stu2[j]->say()) {//			result[MAX_NUM - stu1[i]->id]++;//		}//		else//		{//			result2[MAX_NUM - stu2[j]->id]++;//		}//	}//}//print_score(result, NUM);//print_score(result2, NUM);int result_array1[NUM] = { 0 };merge_array(result, result2, result_array1, NUM);print_score(result_array1, NUM);//multiset<pair<Student*, int>, decltype(asc_sort)> topK(asc_sort);multiset<pair<Student*, int>, decltype(asc_sort)> set1(asc_sort);multiset<pair<Student*, int>, decltype(asc_sort)> set2(asc_sort);cout << "1组胜场详情:";multiset<pair<Student*, int>, decltype(asc_sort)> top1 = print_score(result, NUM, set1);cout << "2组胜场详情:";multiset<pair<Student*, int>, decltype(asc_sort)> top2 = print_score(result2, NUM, set2);cout << "1组前三名如下:" << endl;print_set_no_erase(top1);cout << "2组前三名如下:" << endl;print_set_no_erase(top2);delete[] stu1;delete[] stu2;cout << endl;cout << "---------------------------" << endl;cout << "输入数字1继续第二轮比赛:";int select;cin >> select;if (select != 1) {cout << "第二轮游戏中止......" << endl;return;}//sort(result, result + NUM, greater<int>());//sort(result, result + NUM, asc_sort);Student** s1 = new Student*[3];Student** s2 = new Student*[3];extraction(top1, s1);extraction(top2, s2);cout << "第二轮分组情况:" << endl;cout << "1组: " << endl;print_stu(s1, 3);cout << "2组: " << endl;print_stu(s2, 3);int r1[NUM] = {0};int r2[NUM] = {0};//int* r1 = new int[6]{0};//int* r2 = new int[6]{0};cout << "第二轮总共9场比赛,比赛结果如下:" << endl;competition(s1, s2, 3, r1, r2);//print_score(r1, NUM);//cout << endl;//print_score(r2, NUM);int result_array[NUM] = {0};merge_array(r1, r2, result_array, NUM);print_score(result_array, NUM);//sort(result_array, result_array + NUM, greater<int>());//sort(result_array, result_array + NUM, int_asc_sort);pair<Student*, int> p[NUM];for (int i = 0; i < NUM; i++) {p[i] = make_pair(origin_stu[i], result_array[i]);}sort(p, p+NUM, asc_sort);cout << "前三名信息如下:" << endl;cout << "第一名 id:" << p[0].first->id << " name:" << p[0].first->name << " 总胜场:" << p[0].second << endl;cout << "第二名 id:" << p[1].first->id << " name:" << p[1].first->name << " 总胜场:" << p[1].second << endl;cout << "第三名 id:" << p[2].first->id << " name:" << p[2].first->name << " 总胜场:" << p[2].second << endl;
}// 比赛入口
void entry() {while (true) {int select;cout << "输入1开始,0退出:" ;cin >> select;if (select) {system("cls");cout << "开始游戏..." << endl;cout << endl;main_entry();}else {break;}}cout << "比赛结束..." << endl;
}

http://www.dtcms.com/wzjs/575909.html

相关文章:

  • 网站怎么做用户体验网上书店网站模板
  • dw免费网站模板酒店建筑设计
  • 精通网站开发书籍广告营销号码是干嘛的
  • 自驾游自由行网站建设温州做网站
  • 网站设计网站下35cm
  • wordpress 分类 字段河北网站推广优化
  • seo网站系统wordpress中文界面
  • ps网站CAD做PS地砖贴图杭州模板网站制作方案
  • 重庆网站建设哪个平台好秦皇岛市海港区邮编
  • 沧州做英文网站哪家公司好济南百度竞价开户
  • 淘宝客cms网站模板下载install.php空白 wordpress
  • 网站 设计 电商模板大全免费
  • 网站建设黄页软件如何做网站的悬浮窗口
  • 国外服装购物网站大全游戏开发工程师需要学什么
  • 普通的宣传网站用什么做wordpress免费中文完整版主题下载
  • 模板网站做外贸好不好设计师喜欢的几个网站
  • 如何制作网站建设大型商城购物平台开发
  • 网站建设需求说明书用php做的网站源代码
  • 网站模板抄袭中国移动官方网站
  • 社区信息建设网站有哪些网站可以做全屏代码
  • 58做网站wordpress 定时任务
  • 本地搭建网站怎么在电脑上做网站
  • 做网站需要用服务器吗东莞百度seo电话
  • 深圳网站建设 猴王网络做网站店铺图片用什么软件
  • 企业网站备案需要多久美食网站建设策划方案
  • 龙岗营销网站建设公司哪家好wordpress 商会 模版
  • 做网站需要雇什么人怎么开网页游戏平台
  • ceo是什么职位什么工作网站换空间 seo
  • 广州企业网站建设公司高端网站定制策划
  • 东山网站制作Wordpress简约卡片