十大经典排序算法

20 篇文章 0 订阅
1 篇文章 0 订阅

资料

存一份
桶排序
桶排序代码

例题

1: 桶排序例题

(1)成绩排序

问题

TimeLimit:2000MS MemoryLimit:16MB

Problem Description
编程中数组可以发挥很大的作用,这题就是一例.

Input
输入有多组测试案例,每个测试案例有一行,首先是一个整数n( n <= 5000000),接下来有n个整数,表示每个学生的成绩Ai( 0 <= Ai <= 100)

Output
对于每组测试案例,输出从大到小排序后的成绩,每组测试案例的输出占一行.每两个数字之间有一个空格,行末没有空格。

注意,本题已经重新上传数据并重判。用快速排序算法的会超时(2017-09-05)

SampleInput
5 80 90 100 70 60
4 20 30 50 20

SampleOutput
100 90 80 70 60
50 30 20 20

代码
#include<bits/stdc++.h>
using namespace std;
const int maxsize=1e2+5;
int a[maxsize];
//初始化模块
void input(int * a,int n)  //用于初始化数组,也就是输入用户得分
{
    int i =0;
    int  core;
    for(; i<=100; i++)
        a[i] = 0;    //避免系统初始垃圾数值使他们都为0

    for(i = 0; i<n; i++)
    {
        scanf("%d",&core);   //读取分数
        a[core]++;           //进行计量
    }

}
//降序模块
void descending(int *a,int n)
{
    int i = 101,sum=0;
    int  j;
    for(; i>=0; i--)                  //读取分数,依次判断a[0] ~ a[100]
      for(j = 1; j <= a[i] ; ++ j)  //出现几次就打印几次
        {
            printf("%d",i);
            if(sum<n-1){
              cout<<" ";
              sum++;
            }
         }
  }
int main() {
	// your code goes here
	int n;
	int flag=0;
	while(scanf("%d",&n)!=EOF){
	  input(a,n);
	  descending(a,n);
	  cout<<endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值