题解 | #迭代器遍历set#

迭代器遍历set

https://www.nowcoder.com/practice/7e57c0f7af86429db20c70053f23ea96

#include<bits/stdc++.h>
using namespace std;
int main(){
	set<int>s;
	// write your code here......
	set<int>::iterator it;
	int num;
	for(int i=0;i<5;i++){
		cin>>num;
		s.insert(num);
	}
	for(it=s.begin();it!=s.end();it++){
		cout<<*it<<" ";
	}
	return 0;
}

注意迭代器iterator的用法!!!

for(it=s.begin();it!=s.end();it++){

cout<<*it<<" ";

}

以及set没法用pushback,只能用insert。

全部评论

相关推荐

06-26 10:08
门头沟学院 C++
北京Golang实习,一个月4700,吃住都不报,公司位置在海淀。请问友友怎么看呢?如果要租房的话有什么建议吗
码农索隆:租房肯定是合租了,剩下的钱,差不多够正常吃饭了,看看能不能学到东西吧
点赞 评论 收藏
分享
05-16 11:16
已编辑
东华理工大学 Java
牛客73769814...:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
牛客创作赏金赛
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务