C语言实现排名算法和排位算法

  1 #include "stdio.h"
  2 int search_second_max(int array[], int n,int m)
  3  {
  4      int max1;
  5      int i,num;
  6      num=1;//默认第一名 
  7      if(m>n) return 0; 
  8      max1 = array[m];
  9      for (i = 0; i < n; i++)
 10      {
 11          if (array[i]>max1)
 12          {
 13              num++;      
 14          }
 15 
 16      }
 17      return num;
 18 }
 19 
 20 
 21 void sort(int *a, int l)//a为数组地址,l为数组长度。
 22 {
 23     int i, j;
 24     int v;
 25     //排序主体
 26     for(i = 0; i < l - 1; i ++)
 27         for(j = i+1; j < l; j ++)
 28         {
 29             if(a[i] > a[j])//如前面的比后面的大,则交换。
 30             {
 31                 v = a[i];
 32                 a[i] = a[j];
 33                 a[j] = v;
 34             }
 35         }
 36 }
 37 
 38 //排名 
 39 void  PaiMing(int *a, int *b,int *c,int N)
 40 {
 41     int i, j;
 42     int v;
 43     int arrayindex[8][2];
 44     
 45     for(i=0;i<8;i++)
 46     {
 47        arrayindex[i][0]=a[i];
 48        arrayindex[i][1]=i;
 49     }
 50     //排序主体从小到大 
 51     for(i = 0; i < N - 1; i ++)
 52         for(j = i+1; j < N; j ++)
 53         {
 54             if(arrayindex[i][0] > arrayindex[j][0])//如前面的比后面的大,则交换。
 55             {
 56                 v = arrayindex[i][0];
 57                 arrayindex[i][0] = arrayindex[j][0];
 58                 arrayindex[j][0] = v;
 59                 
 60                 v = arrayindex[i][1];
 61                 arrayindex[i][1] = arrayindex[j][1];
 62                 arrayindex[j][1] = v;
 63                 
 64             }
 65         }    
 66         
 67        //排名次 
 68        for(i=0,j=1;i<N-1;i++)
 69        {
 70              
 71                if(arrayindex[i][0]!=arrayindex[i+1][0])
 72           {
 73                b[i]=j;
 74                j++;
 75                b[i+1]=j;
 76           }else
 77           {
 78                b[i]=j;
 79                b[i+1]=j;
 80           }
 81        } 
 82        
 83        for(i=0;i<N;i++)
 84        {
 85              a[i]=arrayindex[i][0];
 86              c[i]=arrayindex[i][1];
 87        }
 88     
 89 }
 90 
 91  
 92 int main(void)
 93 {
 94    int a[8]={7,2,6,3,3,7,1,8};    
 95    int num;
 96    int i;
 97    int b[8];
 98    int c[8]; 
 99 
100    printf("---------------------------------------\n");
101    
102    PaiMing(a,b,c,8); 
103    for(i=0;i<8;i++)
104    {
105         printf("a[%d]=%d b[%d]=%d c[%d]=%d \n",i,a[i],i,b[i],i,c[i]);
106    } 
107    printf("\n");
108    printf("----------------------------------------\n");
109         
110 
111 
112    
113 }

结果输出

---------------------------------------
a[0]=1 b[0]=1 c[0]=6
a[1]=2 b[1]=2 c[1]=1
a[2]=3 b[2]=3 c[2]=4
a[3]=3 b[3]=3 c[3]=3
a[4]=6 b[4]=4 c[4]=2
a[5]=7 b[5]=5 c[5]=5
a[6]=7 b[6]=5 c[6]=0
a[7]=8 b[7]=6 c[7]=7

----------------------------------------

--------------------------------
Process exited after 0.8098 seconds with return value 0
请按任意键继续. . .

转载于:https://www.cnblogs.com/huangyangquan/p/8391097.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/414802.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

jeesite导出Excel Minimum column number is 0

问题今天在用jeesite(poi)做导出的时候遇到一些问题&#xff01;记录一下.java.lang.IllegalArgumentException: Minimum column number is 0 at org.apache.poi.ss.util.CellRangeAddressBase.validateColumn(CellRangeAddressBase.java:73) at org.apache.poi.ss.util.CellRa…

工作224:当前函数造成

这种报错一般是当前页面的create函数造成的

jQuery基础,javascript

1、获取标签id赋值 $("#data1").text("fwefewfewfwe"); 2、获取表单输入值 var data $("#myForm").serialize(); <input name"username" /></td> <input name"password" type"password"/&g…

在VirtualBox中安装BlackArch Linux

作者&#xff1a;荒原之梦安装前的准备 下载系统映像&#xff1a;BlackArch Linux官网下载页面 在本文中我使用的是BlackArch Linux的Live ISO&#xff0c;这样可以减少安装时下载系统的时间。BlackArch的Live ISO文件有7.5G&#xff0c;我们可以使用BT种子来下载&#xff0c;这…

工作225:当前导致name报错

<!-- <el-form ref"form" :model"form" size"medium" :label-width"formLabelWidth" v-loading"loading"><el-form-item label"订单名称" ><el-input v-model"form.order.name" :dis…

Maven的安装以及在Myeclipse上的配置——超详细

在网上找了配置maven的文章&#xff0c;感觉还是有点图文会比较方便查看。 一&#xff1a;Maven的下载安装 准备工作&#xff1a; 1)安装环境 Windows 7 2)需安装JDK ,并配置环境变量(略) 3) Maven版本3.0.5 4)下载地址:http://mirror.bit.edu.cn/apache/maven/maven-3/3.0.5/b…

myeclipse中如何在整个工程中搜索字符串

看图点击即可。项目——>Search——>File 选择搜索条件

十五. Python基础(15)--内置函数-1

十五. Python基础(15)--内置函数-1 1 ● eval(), exec(), compile() 执行字符串数据类型的python代码 检测#import os import in code ① eval : 有返回值, 适用于执行计算语句, 例如eval("43"). ② exec : 没有返回值, 适用于执行流程控制语句, 例如exec(a b if b&…

工作226:for循环逻辑

<el-form v-for"(cep,index) in form.detpartment_amount" ><el-form-item label"部门账号"><el-input v-model"cep.name"></el-input></el-form-item><el-form-item label"传播量"><el-inpu…

myeclipse中添加Oracle数据库

打开Myeclipse后点击如图右上方进入MyEclipse Database Explorer视图 在如图空白处鼠标右击后点选new进入Create a new connection driver界面 在Driver template:中下拉选中Oracle(Thin driver); 在Driver name中填写你希望的名称&#xff1b; 在Connection URL中将后面…

SSM(Spring+SpringMVC+Mybatis)框架环境搭建(整合步骤)(一)

SSM(SpringSpringMVCMybatis)框架环境搭建(整合步骤)(一) 1. 前言 最近在写毕设过程中&#xff0c;重新梳理了一遍SSM框架&#xff0c;特此记录一下。 附上源码&#xff1a;https://gitee.com/niceyoo/jeenotes-ssm 2. 概述 在写代码之前我们先了解一下这三个框架分别是干什么…

Spring事务管理详解_基本原理_事务管理方式

Spring事务管理详解_基本原理_事务管理方式 1. 事务的基本原理 Spring事务的本质其实就是数据库对事务的支持&#xff0c;使用JDBC的事务管理机制,就是利用java.sql.Connection对象完成对事务的提交&#xff0c;那在没有Spring帮我们管理事务之前&#xff0c;我们要怎么做。 C…

ORA-28000: the account is locked

首先使用具有sysdba权限的账户登陆&#xff0c;如sys账户和system账户 新建一个sql窗体&#xff0c;并执行语句解锁被锁定的账户&#xff0c;如我这里sgyw账户&#xff1a; alter user sgyw account unlock; 执行成功后再次用这个账户就可以登陆系统了。

工作227:小程序学习1开始布局页面

<template><view class"box u-p-l-35 u-p-r-35 "><view class"title"><text>请选择您要管理的市场</text></view><view :class" [u-flex,u-row-center,{choose_market: selectIndex 0},{market : selectIndex…

windows下安装和使用scrapy

首先&#xff0c;要确保已经正确安装了python环境&#xff0c;并安装了pip包 接着&#xff0c;打开cmd或者powershell &#xff0c;输入命令 pip install scrapy 。安装完之后 运行scrapy性能测试命令&#xff1a; scrapy bench 。此时可能出现“import win32api&#xff0c;Im…

spring声明式事务管理方式( 基于tx和aop名字空间的xml配置+@Transactional注解)

1. 声明式事务管理分类 声明式事务管理也有两种常用的方式&#xff0c; 一种是基于tx和aop名字空间的xml配置文件&#xff0c;另一种就是基于Transactional注解。 显然基于注解的方式更简单易用&#xff0c;更清爽。 2. spring事务特性 spring所有的事务管理策略类都继承自org.…

oracle中如何设置主键并且让其自动增长

1、创建数据库 create table USERINFO ( USERNO NUMBER not null, USERNAME NVARCHAR2(20), USERPWD NVARCHAR2(20) ) 2、创建触发器 create sequence SEQ_Userinf start with 1 increment by 1 nomaxvalue nominvalue nocache; CREATE OR REPLACE TRIGGER tg_test BEFORE …

工作228:小程序学习2开始布局页面2

<template><view class"box u-p-l-35 u-p-r-35 "><view class"title"><text>请选择您要管理的市场</text></view><view :class" [u-flex,u-row-center,{choose_market: selectIndex 0},{market : selectIndex…

AngularJs通过路由传参解决多个页面资源浪费问题

在实际开发中会遇到很多类似模块界面大体都一致只是极少的细节部分不一样&#xff0c;这时不管是在html页面还有js及数据交互的时候我们就没必要因为这些不同的页面分出不同的文件&#xff0c;这样很浪费内存及效率&#xff0c;于是我在开发中想到一种办法&#xff1a;通过ng路…

mybatis BindingException: Invalid bound statement (not found)

错误截图 解决措施 此异常的原因是由于mapper接口编译后在同一个目录下没有找到mapper映射文件而出现的。 通常我们在配置SqlSessionFactory时会有如配置 1 <!-- 配置SqlSessionFactory -->2 <bean class"org.mybatis.spring.SqlSessionFactoryBean">…