标签:\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