码迷,mamicode.com
首页 > 编程语言 > 详细

计数排序

时间:2017-07-22 14:28:17      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:put   ++   set   div   turn   article   for   pos   ret   



#include<stdio.h>
#include<string.h>
int nTestCase[300001];
int nNumbers[32001];
int main()
{
	freopen("sample_input.txt","r",stdin);

	int i, j, test, currrank, n, max;
	scanf("%d", &test);
	while (test--){
		currrank = 1; max = 0;
		scanf("%d", &n);
		memset(nNumbers, 0, 32000 * sizeof(int));
		for (i = 1; i <= n; i++){
			scanf("%d", &nTestCase[i]);
			nNumbers[nTestCase[i]]++;
			max = max<nTestCase[i] ?

nTestCase[i] : max; } for (i = max; i>0; i--){ if (nNumbers[i]){ j = nNumbers[i]; nNumbers[i] = currrank; currrank += j; } } for (i = 1; i <= n; i++) printf("%d ", nNumbers[nTestCase[i]]); printf("\n"); } return 0; }



计数排序

标签:put   ++   set   div   turn   article   for   pos   ret   

原文地址:http://www.cnblogs.com/gavanwanggw/p/7221007.html

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