https://vjudge.net/problem/UVA-11462

题意:

给出一堆范围在1到100的数,叫排序。

思路:

水。。。计数,然后排序就可以了。

代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 int a[105];
 5 
 6 int main()
 7 {
 8     int n;
 9 
10     while (scanf("%d",&n) != EOF && n)
11     {
12         memset(a,0,sizeof(a));
13 
14         int cnt = 0,num = 0;
15 
16         for(int i = 1;i <= n;i++)
17         {
18             int x;
19 
20             scanf("%d",&x);
21 
22             a[x]++;
23 
24             cnt++;
25         }
26 
27         for (int i = 1;i <= 100;i++)
28         {
29             if (a[i])
30             {
31                 for (int j = 1;j <= a[i];j++)
32                 {
33                     if (num == cnt - 1) printf("%d\n",i);
34                     else
35                     {
36                         printf("%d ",i);
37                         num++;
38                     }
39                 }
40             }
41         }
42     }
43 
44     return 0;
45 }

 

相关文章:

  • 2022-12-23
  • 2022-01-25
  • 2022-12-23
  • 2021-06-11
  • 2022-03-03
  • 2021-12-05
  • 2021-08-17
  • 2021-09-10
猜你喜欢
  • 2022-12-23
  • 2021-10-01
  • 2022-01-29
  • 2022-03-03
  • 2021-11-21
  • 2021-08-04
  • 2022-12-23
相关资源
相似解决方案