vector
int main(){
int v[] = {1,2,3,4,5} ;
vector<int> v(100,-1);//定义一个v包含100个数初始化为-1
vector<int> a(v, v+5);//整体赋值
//sort(a,a+10);
//sort(a.begin(), a.end()) ;
//reverse(a.begin(), a.end()) ;//倒序
a.erase( a.begin() +1, a.begin() +4);
for(auto i : a){
cout << i<<" ";
}
return 0;
}
map
int main(){
map<string,int> mp; //定义一个string到int的映射
string x;
while(cin >> x){
mp[x] += 1;//统计
}
cout << mp.count("uuu") <<endl;//查找是否存在
cou << " " << mp["uuu"] << endl;//查找出现的次数
for(auto i : mp){
cout <<i.first << " " << i.second << endl;
}
return 0;
}
set
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[] = {1,3,2,2,4};
set<int> st(a, a+5);//整体赋值
st.insert(1);//输入
st.insert(3); st.insert(2); st.insert(2);
st.insert(4);
auto it = st.find(3);//查找
if(it == st.end()) cout << "no";
else cout << "yes";
auto ite = st.end();
--ite;
cout << endl << *ite << endl;//最大值
cout << *st.begin() << endl;//最小值
for(auto i : st){ //遍历
cout << i << " ";
}
return 0;
}
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com