解法一:
用sort
int main()
{
int i, j, k, a[2000001];
int m, n;
cin >> m;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a, a + n);
for (i = 0; i < n; i++)
{
cout << a[i] << ' ';
}
}//常规思路常规方法,最简单
解法二:
计数排序
int main()
{
int i, j, k, a[1000] = { 0 };//虽然n<=999,但是起始数组是i=1,最好一开始多设几个
int m, n;
cin >> m;//5
cin >> n;//10
for (i = 1; i <= n; i++)
{
cin >> k;
a[k]++;
}
for (i = 1; i <= m; i++)
{
while (a[i]>0)
{
a[i]--;
cout << i << ' ';
}
}
}