真不严谨 最后面的那个空格我看输出格式明明没有
查看原帖
真不严谨 最后面的那个空格我看输出格式明明没有
955061
wang65535楼主2023/3/7 16:00
#include <iostream>
#include <string>
#include <limits.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
    srand((unsigned)time(NULL));
    int n;
    cin >> n;
    int a[n];
    set<int> s;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        s.insert(a[i]);
    }
    int len = s.size();
    cout << len << "\n";
//    for(set<int>::iterator it = s.begin(); it != s.end(); it++){
//
//        cout << *it << " ";
//    }
    //另一种遍历
    while(!s.empty()){
        cout << *s.begin() << " ";
        s.erase(s.begin());
    }
    return 0;
}

2023/3/7 16:00
加载中...