码迷,mamicode.com
首页 > 其他好文 > 详细

等值并列排名(学生成绩排名)

时间:2018-08-29 10:40:19      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:\n   div   数组   ret   代码   else   int   ==   inf   

#include<stdio.h>
int main(void){
    int count[22]={7,7,5,5,4,4,4,4,3,3,3,3,2,2,2,2,1,1,1,1,1,1};//已排好序待排名的数组
    int s[22];//根据count数组分别加入排名次序
    int i,j;
    int k,result;
    k=1;result=1;
    for(i=0;i<22;i++){
        if(i==0){
        s[i]=k;
        }
        else if(i>0&&count[i]!=count[i-1]){
        k++;
        result++;
        s[i]=k;
    
        }
        else if(i>0&&count[i]==count[i-1]){
        s[i]=result;
        k++;
        if(i<22&&count[i]!=count[i+1]){
        result=k;
        }
        }
    }
    for(j=0;j<22;j++){
        printf("%d      %d\n",count[j],s[j]);
    }
    return 0;
}

技术分享图片

运行结果如图所示,代码没有经过优化,只是实现了排名功能。

 

等值并列排名(学生成绩排名)

标签:\n   div   数组   ret   代码   else   int   ==   inf   

原文地址:https://www.cnblogs.com/zwk2018/p/9552187.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!