UVa 11462 - Age Sort
传送门
题意
从小到大输出每个人的年龄。
思路
放到一个数组里,按照数量输出。
代码
#include <bits/stdc++.h>
#define LL long long
#define lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
using namespace std;
const int MAXN = 100 + 5;
const int INF = 0x3f3f3f3f;
int age[MAXN];
struct POS
{
int x, y;
}dd;
inline int ReadInt()
{
static int r, sign;
static char ch;
r = 0, sign = 1;
while ((ch = getchar()) && !isdigit(ch));
if (ch == '-')
sign = -1, ch = getchar();
while (isdigit(ch))
r = r * 10 + ch - '0', ch = getchar();
return sign * r;
}
int main()
{
//freopen("input.txt", "r", stdin);
int n, i, j;
while (scanf("%d", &n), n)
{
int first = 1;
memset(age, 0, sizeof age);
for (i = 0; i < n; i++)
{
j = ReadInt();
age[j]++;
}
for (i = 1; i < MAXN; i++)
for (j = 0; j < age[i]; j++)
{
if (!first) printf(" ");
first = 0;
printf("%d", i);
}
puts("");
}
return 0;
}