计数排序
来源:互联网 发布:有首单立减的外卖软件 编辑:程序博客网 时间:2024/05/16 12:03
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;const int MAX = 100000;const int k=1000;//a为输入数组,rank为输出顺序,c[i]表示i出现的次数int a[MAX],c[MAX],rank[MAX];void jsort(int n){ memset(c,0,sizeof(int)*MAX); //初始化c数组 //检查每个输入元素,如果一个输入元素值为5,那么c[5]++;c[i]中存放了值为i的元素的个数 for(int i=0;i<n;i++) c[a[i]]++; //通过在c中记录计数和,c[i]中存放的是小于等于i的元素的数字个数 for(int i=1;i<k;++i) c[i]+=c[i-1]; //rank记录每个数字的输出顺序 for(int i=n-1;i>=0;--i) rank[--c[a[i]]]=i; for(int i=0;i<n;++i) cout<<a[rank[i]]<<endl;}int main(){ int n; scanf("%d",&n); for(int i=0;i<n;++i) scanf("%d",&a[i]); jsort(n); return 0;}
0 0
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- 计数排序
- SSH,不支持从 date 到 BINARY 的转换
- Ubuntu10.10时间/时区设置
- Mysql error 1452 - Cannot add or update a child row: a foreign key constraint fails
- C语言允许数组下标是负数
- poj_1328 贪心
- 计数排序
- 存储过程的一些东西
- 让QQ的tadb.exe 不自动启动
- Ruby on Rails,数据库迁移命令和迁移任务编写
- 黑马程序员_OC基础09_block
- UPnP协议编程实践
- myeclipse 上安装 Maven3
- ant编译android程序
- 图论500题