douyuan9512 2016-01-21 20:55
浏览 23
已采纳

php中的复杂排名

I have been battling out with a bit of a complex ranking system.The ranking depend on students points which are independent of marks. The point calculation is okay with me. The problem comes in when breaking ties because that depends on student marks which is a different entity altogether. Students can have similar points but differ in marks which can be used to break a tie in case some students tie on points. I need help because i got stuck. Please refer to my picture to get a rough idea and tell me if it can be done. I have also included some of my code.

A visual illustration

<?php
$rank_by_point=array();
//loop out students and get their admission number from which you calculate individual points based on an algorithm
foreach($students as $student => $student_no){
 array_push($rank_by_point[$student_no],calculatePoints($student_no));
}
//sorting the points from highest to lowest
arsort($rank_by_point);

//the ranking code down here
$ties=array();
$break=array();
$initial_positions=array();
$rank = 0;
$last = false;
foreach($rank_by_point as $key => $value){
  if($last != $value){
     $last = $value;
     $rank++;                 
  }else{
    //when a tie is detected add the values to a tie array
    array_push($ties[$key],$rank);
  }
  array_push($initial_positions[$key],$rank);
}
//spliting of ties is done by getting marks and rearrangin the tie
foreach($ties as $admno => $st_rank){
  $read_position=$rank;//same value for all keys in the ties array
  $getmarks=getMarks($admno);
  array_push($break[$admno],$getmarks);
  //reorder the array in desc order
  arsort($break);
}
//reranking the ties. i got stuck here :-(
?>
  • 写回答

2条回答 默认 最新

  • dongyan1936 2016-01-21 21:21
    关注
    1. Add student marks as a smaller score into calculatePoints($student_no). e.g.

       function calculatePoints($student_no){
      
           /*add this before return it*/
      
           $point = $point*1000;//make sure the new $point be bigger than the max $student_mark
      
           $point += $student_mark;
      
           return $point;
       }
      
    2. sort as you did now

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?