共有n名学生的成绩 每位学生的成绩a均为0-100之间的自然数 从小到大排序后输出同学们的成绩 相同成绩只输出一次 C++

题目

期中考试结束,小童帮助完成学生成绩统计工作。共有n名学生的成绩,每位学生的成绩a均为0-100之间的自然数。从小到大排序后输出同学们的成绩,相同成绩只输出一次。
用C++实现

我想要达到的结果

输入:
10
10 30 50 70 50 30 10 20 0 100

输出:

0 10 20 30 50 70 100


#include <iostream>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    for(int i = 0;i < n - 1;i++){
        for(int j = 0;j < n - 1 - i;j++){
            if(a[j] > a[j+1]){
                int temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }
    cout << a[0] << " ";
    for(int i = 1;i < n;i++){
        if(a[i] != a[i-1]){
            cout << a[i] << " ";
        }
    }
    return 0;
}

vector<int> func(vector<int> nums) {
    int n = nums.size();
    vector<int> mask(101,-1);
    vector<int> res;
    for (int n : nums) {
        mask[n]++;
    }
    for (int i = 0; i <= 100;i++) {
        if (mask[i] != -1)
            res.push_back(i);
            
    }
    return res;
}
int main()
{
    int n;
    cin >> n;
    vector<int> nums;
    for (int i = 0; i < n; i++)
        cin >> nums[i];
    auto ans = func(nums);
    for (int x : ans)
        cout << x <<" ";
    
}