计数排序

来源:互联网 发布:传媒大数据 编辑:程序博客网 时间:2024/06/04 18:41
 
 
计数排序:员工年龄排序
 
原题在这里:
http://ac.jobdu.com/problem.php?cid=1039&pid=16

 
#include<stdio.h>

 
int Counter[100];

int SortEmployee()
{
int Count = 0;
int Index = 0;
int offset = 0;
int Input = 0;
while(scanf("%d",&Count) == 1)
{
offset = 0;
for (Index = 0; Index<100; ++Index)
{
Counter[Index] = 0;
}
for (Index = 0; Index<Count;++Index)
{
scanf("%d",&Input);
++Counter[ Input ];
}
for (Index = 1; Index<100; ++Index)
{
for(int i = 0; i<Counter[Index];++i)
{
//Output[offset++] = Index;
printf("%d ",Index );
}
}
printf("\n");
}

return 0;
}
int main(int argc, char const *argv[])
{
SortEmployee();
return 0;
}