题解 | #明明的随机数#

明明的随机数

https://www.nowcoder.com/practice/3245215fffb84b7b81285493eae92ff0

#include <cstdio>
#include <iostream>
#include <set>
using namespace std;

int main() {
    int n;
    cin >> n;
    set<int> st;
    int vi = 0;
    for (int i = 0; i <= n; i++) {
        int a;
        cin >> a;
        st.insert(a);
    }
    for(set<int>::iterator it = st.begin(); it != st.end(); it ++)
    {
        printf("%d\n", *it); 
    }
    
}

全部评论
这道题是量身为set这个容器打造的,set翻译为集合,是一个内部自动有序,且不含重复元素的容器 需要注意的是set只能通过迭代器iterator来访问
点赞 回复 分享
发布于 2023-11-28 22:08 浙江

相关推荐

求面试求offer啊啊啊啊:1600一个月?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务