您的位置:首页 > 其它

UVa 11462 - Age Sort

2013-04-10 15:16 309 查看
  由于输入数据数量很大,但是数据的范围很小,所以用计数排序,代码如下:

View Code

#include <cstdio>
#include <cstring>

int main()
{
int n, x, cnt[101];
while(scanf("%d", &n) != EOF && n)
{
memset(cnt, 0, sizeof(cnt));
for(int i = 0; i < n; i++)
{
scanf("%d", &x);
cnt[x]++;
}
int first = 1;
for(int i = 1; i <= 100; i++)
for(int j = 0; j < cnt[i]; j++)
{
if(first)   first = 0;
else printf(" ");
printf("%d", i);
}
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: