桶排序-题解

描述

输入n个数字,并去重、从小到大排序。

输入描述

第一行:一个正整数n(n<=100)
第二行:n个整数a(-100<=a<=100)

输出描述

一行,排序后的数组。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;

int main(){
bool buck[201]={false};
int n,tmp;
cin >> n;
for (int i = 0;i<n;i++){
cin >> tmp;
buck[tmp+100]=true;
}
for(int j = 0;j<201;j++){
if(buck[j]){
cout << j-100 << " ";
}
}
return 0;
}


桶排序-题解
https://chenxi-tijie.pages.dev/2025/06/桶排序-题解/
作者
chenxi
发布于
2025年6月8日
许可协议