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

珠海营销网站建设/个人网站推广

珠海营销网站建设,个人网站推广,做易买网网站项目心得体会,国家新闻出版题目 程序设计能力实训是华东师范大学计软院让学生非常头痛的一门课程,课程考试旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,每次考试会有多个考场同时进行考试,假设每个考场会在考试结束后产生一…

题目

程序设计能力实训是华东师范大学计软院让学生非常头痛的一门课程,课程考试旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,每次考试会有多个考场同时进行考试,假设每个考场会在考试结束后产生一份学生成绩,之后将各个考场的成绩汇总为一份总的成绩单,现在请你对这张总的成绩单进行排名。
在这里插入图片描述

思路

实训,我的痛苦面具
需要注意的是,同分的同学排名一致。虽然输出时学号为第二关键字,但在赋排名时不能简单+1。
需要考虑遍历每个考场中的学生时数组越界的问题。

方法1

简单的做法是用库函数sort,由于二维数组行分布并不均匀,处理起来有点麻烦(其实是太菜处理不好),所以将排好序的二维数组拷贝进一个一维数组重新排序。

方法2

由于题目要求,已经排好了各小数组的顺序,考虑使用归并排序。

代码

方法1

#include<bits/stdc++.h>
using namespace std;struct student
{long long numStu;  // 学号int rankAll;  // 所有人中的排名int numTest;  // 考场号int rankLoc;  // 本考场中的排名int score = -1;  // 分数
};bool cmp1(student a, student b)
{if (a.score != b.score)return a.score > b.score;else return a.numStu < b.numStu;
}int main()
{int n; cin >> n;int allStu = 0;student** a = new student * [n + 1];int* tmpNumTest = new int[n + 1];for (int i = 1; i <= n; i++)// 考场号为i{int numTest; cin >> numTest;allStu += numTest;a[i] = new student[numTest];tmpNumTest[i] = numTest;for (int j = 0; j < numTest; j++){a[i][j].numTest = i;long long numStu;int score;cin >> numStu >> score;a[i][j].numStu = numStu;a[i][j].score = score;}sort(a[i], a[i] + numTest, cmp1);//for (int j = 0; j < numTest; j++)//{//	a[i][j].rankLoc = j + 1;//}a[i][0].rankLoc = 1;int kk = 1;int step = 1;while (kk<numTest){if (a[i][kk].score == a[i][kk - 1].score){a[i][kk].rankLoc = a[i][kk - 1].rankLoc;kk++;step++;}else{a[i][kk].rankLoc = a[i][kk - 1].rankLoc + step;kk++;step = 1;}}//cout << "*************" << endl;//for (int j = 0; j < numTest; j++)//{//	cout << a[i][j].numStu << ' ' << a[i][j].numTest << ' '<< a[i][j].rankLoc << endl;//}}cout << allStu << endl;student* res = new student[allStu + 1];int idxRes = 0;for (int i = 1; i <= n; i++){for (int j = 0; j < tmpNumTest[i] && a[i][j].score != -1; j++){res[idxRes].numStu = a[i][j].numStu;res[idxRes].numTest = a[i][j].numTest;res[idxRes].rankLoc = a[i][j].rankLoc;res[idxRes].score = a[i][j].score;idxRes++;}}sort(res, res + allStu, cmp1);res[0].rankAll = 1;int ii = 1;int sstep = 1;while (ii < allStu){if (res[ii].score == res[ii - 1].score){res[ii].rankAll = res[ii - 1].rankAll;sstep++;}else{res[ii].rankAll = res[ii - 1].rankAll + sstep;sstep = 1;}ii++;}for (int i = 0; i < allStu; i++){cout << res[i].numStu << ' ' << res[i].rankAll << ' ' << res[i].numTest << ' ' << res[i].rankLoc << endl;}return 0;
}

方法2

#include<bits/stdc++.h>
using namespace std;
#define K 300struct student
{long long numStu;  // 学号int rankAll;  // 所有人中的排名int numTest;  // 考场号int rankLoc;  // 本考场中的排名int score = -1;  // 分数
};bool cmp1(student a, student b)
{if (a.score != b.score)return a.score > b.score;else return a.numStu < b.numStu;
}int main()
{int n; cin >> n;int allStu = 0;student** a = new student * [n + 1];int* tmpNumTest = new int[n + 1];for (int i = 1; i <= n; i++)// 考场号为i{int numTest; cin >> numTest;allStu += numTest;a[i] = new student[K];tmpNumTest[i] = numTest;for (int j = 0; j < numTest; j++){a[i][j].numTest = i;long long numStu;int score;cin >> numStu >> score;a[i][j].numStu = numStu;a[i][j].score = score;}sort(a[i], a[i] + numTest, cmp1);a[i][0].rankLoc = 1;int kk = 1;int step = 1;while (kk < numTest){if (a[i][kk].score == a[i][kk - 1].score){a[i][kk].rankLoc = a[i][kk - 1].rankLoc;kk++;step++;}else{a[i][kk].rankLoc = a[i][kk - 1].rankLoc + step;kk++;step = 1;}}//cout << "*************" << endl;//for (int j = 0; j < numTest; j++)//{//	cout << a[i][j].numStu << ' ' << a[i][j].numTest << ' '<< a[i][j].rankLoc << ' ' << a[i][j].score<<endl;//}}cout << allStu << endl;student* res = new student[allStu + 1];int* head = new int[n+1];memset(head, 0, sizeof(int) * (n + 1));int idxRes = 0;//int maxScore = 0;//int maxIdx = 1;while (idxRes<allStu){int maxScore = 0;int maxIdx = 1;for (int i = 1; i <= n; i++)// 遍历每一个考场{if (head[i] >= tmpNumTest[i]) continue;  // 考虑数组越界问题if (a[i][head[i]].score>maxScore || (a[i][head[i]].score==maxScore && a[i][head[i]].numStu<=a[maxIdx][head[maxIdx]].numStu)){maxScore = a[i][head[i]].score;maxIdx = i;}}res[idxRes].score = maxScore;res[idxRes].numStu = a[maxIdx][head[maxIdx]].numStu;res[idxRes].numTest = a[maxIdx][head[maxIdx]].numTest;res[idxRes].rankLoc = a[maxIdx][head[maxIdx]].rankLoc;head[maxIdx]++;idxRes++;maxIdx= maxIdx==1?maxIdx+1:maxIdx-1;}res[0].rankAll = 1;int ii = 1;int sstep = 1;while (ii < allStu){if (res[ii].score == res[ii - 1].score){res[ii].rankAll = res[ii - 1].rankAll;ii++;sstep++;}else{res[ii].rankAll = res[ii - 1].rankAll + sstep;ii++;sstep = 1;}}for (int i = 0; i < allStu; i++){cout << res[i].numStu << ' ' <<res[i].rankAll<<' ' << res[i].numTest << ' ' << res[i].rankLoc << endl;}return 0;
}
http://www.jmfq.cn/news/4943917.html

相关文章:

  • 组织建设是什么/网站seo排名培训
  • 车机油哪个网站做的好/it培训班
  • 长沙网上商城网站建设方案/百度数据分析工具
  • 成都 网站建设 公司/全球网站流量排名查询
  • 广西网络网站建设/推广资源网
  • 广州疫情最新动态知乎/企业站seo外包
  • 如何建设移动端网站/网站建设方案开发
  • 单页网站模板做seo/宁波 seo排名公司
  • 网站字体字号/网络广告宣传平台
  • 淘宝客建立网站/可以访问违规网站的浏览器
  • 梁山做网站价格/优化大师软件大全
  • 网站搭建素材/1000个关键词
  • 网站开发 案例/关键词有几种类型
  • 网站建设定制/推广代运营公司
  • ping一下新浪网站怎么做/网络服务器搭建
  • 南京宜电的网站谁做的/重庆seo网络营销
  • wnmp搭建后怎么做网站/seo外链网
  • 北京广告公司聚集地/深圳网络优化推广公司
  • 云服务器和网站备案/廊坊关键词快速排名
  • 网站设计在线培训/网站建设的基本
  • 自建网站模板/已备案域名交易平台
  • 网站建设费用报价表/公司网址有哪些
  • 做国外的众筹网站/商丘seo推广
  • 动态网站建设编程/成人电脑基础培训班
  • 贸易型企业网站建设/网络营销买什么好
  • 哈尔滨网络优化推广公司/seo官网优化详细方法
  • 专门做建筑设计图库的网站设计/软文营销的五大注意事项
  • 许昌网站建设公司/热点新闻事件
  • 昆山做网站怎么做/36优化大师下载安装
  • 福州网站建设找嘉艺网络/推广网