2022-08-03 算法学习——集合的遍历,同时推广到stl容器的遍历

include<bits/stdc++.h>

using namespace std;
set <int> st;
int n;
int main() {
scanf("%d",&n);
for(int i=0;i<n;i++) {
int tmp;
scanf("%d",&tmp);
st.insert(tmp);
}
//集合的遍历
for(auto it = st.begin();it!=st.end();it++) {
cout<<it<<endl;
}
//返回极差
set < int > ::iterator it= --st.end();
cout<<
it - *st.begin();
return 0;
}

posted @ 2024-02-25 21:25  lovevivi121  阅读(15)  评论(0)    收藏  举报  来源