关于哈希表
unordered_map<std::string, int> words
通过words[(string类型数据)]对哈希表进行操作
unordered_map4种遍历方式
for(pair<int,int> kv:map){
cout<<kv.first<<kv.second<<endl;
}
for(const pair<int,int>& kv:map){
cout<<kv.first<<kv.second<<endl;
}
for(unordered_map<int,int>::iterator it=map.begin();it!=map.end();it++){
cout<first<second<<endl;
}
for(auto [k,v]:map){
cout<<k<<v<<endl;
}
其他
stringstream ss; //stream根据空格分词
关于大根堆
priority_queue q(nums.begin(),nums.end());
int x=q.top();
q.pop();
ans+=x;
q.push((x+2)/3);
关于vector
vector简单笔记:
vector删除指定元素 v.erase(v.begin() + 2); // 删除第3个元素
可以通过访问数组方式对vector访问,a[0]。
对添加元素用push_back方法。a.push_back(1)
vector.end()指向的是最后一个元素的下一个位置
方法中作为参数需要改动时添加&符号表示引用。
emplace_back方法对值进行构造
随便写写
stack<pair<int,int>> st;
stack的方法 st.top()读取栈顶元素,st.push st.pop 压栈弹栈 empty()判空
pair表示一对数,用.first .second访问
sscanf(log.c_str(),“%d:%[^:]:%d”,&idx,type,&time);
%[^:]--------正则(读到:字符)
string类型substr方法 substr( 1 , 2) 从第一个位置开始读取长度为2的字符串