<Standard Template Library>标准模板库专项复习总结(一)
看了看博客园的申请时间也一年多了...想想自己一年多以来一直处于各种划水状态,现在又要面临ACM的冲击...
还是要抓紧时间赶紧复习一下了- -毕竟校园新生赛还是有奖金的..
1.栈
先进后出(LIFO)表
头文件:#include<stack>
变量的定义:stack<TYPE>StackName
成员函数:
bool empty() 栈为空返回true,否则返回false
void pop() 删除栈顶元素
void push(const TYPE &val) 进栈
size_type size() 返回栈的数目
TYPE& top() 查看栈首
2.动态数组
头文件:#include<vector>
变量的定义:vector<TYPE>vectorName
成员函数:
TYPE& size() 返回数组的数目
bool empty() 数组为空返回true,否则返回false
void clear() 清空数组
* begin() 返回第一个数据的地址
* end() 返回最后一个数据的地址
void pop_back() 删除最后一个数据
* insert(a,b) 在a位置插入b
void insert(a,n,b) 在a位置插入n个b
void insert(a,beg,end) 在a位置插入beg到end之间的数据
void swep(vector) 互换两个vector
3.映射
头文件:#include<map>
变量的定义:map<TYPE,TYPE>mapName
map<key,elem> 一个map,以less<>为排序准则 map<key,elem,op> 一个map,以op为排序准则
另外需要定义迭代器(iterator)
map<string,float>::iterator pos;
类似于指针,解释一下就是:
当迭代器pos指向map中的某个元素,表达式pos->first获得该元素的key,表达式pos->second获得该元素的value
举个例子:(摘自https://blog.csdn.net/shawn_hou/article/details/38035577)
#include <map>
#include <string>
#include <iostream>
using namespace std;
int main()
{
map<int, string> mapStudent;
mapStudent.insert(pair<int, string>(, "student_one"));
mapStudent.insert(pair<int, string>(, "student_two"));
mapStudent.insert(pair<int, string>(, "student_three"));
map<int, string>::iterator iter;
for(iter = mapStudent.begin(); iter != mapStudent.end(); iter++)
cout<<iter->first<<' '<<iter->second<<endl;
}

成员函数:
iterator begin() 返回指向第一个元素的迭代器
iterator end() 返回指向最后一个元素的迭代器
void clear() 清空map
bool empty() 返回是否map为空
void insert() 插入
TYPE& size() 返回map大小
*也可以直接使用pair类型输入
#include<cstdio>
#include<iostream>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#define MAXN
using namespace std;
int n,x,y;
int main(){
ios::sync_with_stdio(false);
map<int,int>m;
m.insert(pair<int,int>(,));
cin>>n;
for(register int i=;i<=n;i++){
cin>>x>>y;
pair<int,int> p (x,y);
m.insert(p);
} cout<<endl;
for(register map<int,int>::iterator i=m.begin();i!=m.end();i++){
pair<int,int>it=*i;
cout<<it.first<<" "<<it.second<<endl;
}
return ;
}
原文:https://blog.csdn.net/NOIAu/article/details/72923307
------对于没有数据结构基础的小白,比如不知道什么是迭代器什么是pair可以自行百度
总而言之,map=pair+set
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;
int main(){
map<string,float> c;
c.insert(make_pair("Cafe",7.75));
c.insert(make_pair("Banana",1.72));
c["Wine"]=15.66;
map<string,float>::iterator pos;
for(pos=c.begin();pos!=c.end();pos++){
cout<<pos->first<<" "<<pos->second<<endl;
}
return ;
}
<Standard Template Library>标准模板库专项复习总结(一)的更多相关文章
- <Standard Template Library>标准模板库专项复习总结(二)
4.队列 先进先出(FIFO)表 头文件:#include<queue> 变量的定义:queue<TYPE>queueName 成员函数: bool empty() 空队列返回 ...
- C++ 标准模板库(STL)
C++ 标准模板库(STL)C++ STL (Standard Template Library标准模板库) 是通用类模板和算法的集合,它提供给程序员一些标准的数据结构的实现如 queues(队列), ...
- link-1-STL 标准模板库
STL(Standard Template Library,标准模版库)是C++语⾔言标准中的重要组成部分.STL以模板类和模版函数的形式为程序员提供了了各种数据结构和算法的实现,程序员吐过能够充分的 ...
- C++标准模板库Stand Template Library(STL)简介与STL string类
参考<21天学通C++>第15和16章节,在对宏和模板学习之后,开启对C++实现的标准模板类STL进行简介,同时介绍简单的string类.虽然前面对于vector.deque.list等进 ...
- STL标准模板库(简介)
标准模板库(STL,Standard Template Library)是C++标准库的重要组成部分,包含了诸多在计算机科学领域里所常见的基本数据结构和基本算法,为广大C++程序员提供了一个可扩展的应 ...
- 【转】C++标准库和标准模板库
C++强大的功能来源于其丰富的类库及库函数资源.C++标准库的内容总共在50个标准头文件中定义.在C++开发中,要尽可能地利用标准库完成.这样做的直接好处包括:(1)成本:已经作为标准提供,何苦再花费 ...
- C++ Standard Template Library STL(undone)
目录 . C++标准模版库(Standard Template Library STL) . C++ STL容器 . C++ STL 顺序性容器 . C++ STL 关联式容器 . C++ STL 容 ...
- 【c++】标准模板库STL入门简介与常见用法
一.STL简介 1.什么是STL STL(Standard Template Library)标准模板库,主要由容器.迭代器.算法.函数对象.内存分配器和适配器六大部分组成.STL已是标准C++的一部 ...
- STL 简介,标准模板库
这篇文章是关于C++语言的一个新的扩展--标准模板库的(Standard Template Library),也叫STL. 当我第一次打算写一篇关于STL的文章的时候,我不得不承认我当时低估了这个话 ...
随机推荐
- Nginx 外的另一选择,轻量级开源 Web 服务器 Tengine 发布新版本
新版发布 近日,轻量级开源 Web 服务器 Tengine 发布了2.3.0版本,新增如下特性: ngx_http_proxy_connect_module,该模块让 Tengine 可以用于正向代理 ...
- pycharm 永久注册
pycharm 使用又到期了,找到了破解版亲测(到期日期2099/12/31),绝对简单好用,直接使用步骤: 一,下载pycharm(windows版): https://www.jetbrains ...
- 【JZOJ4878】【NOIP2016提高A组集训第10场11.8】时空传送
题目描述 经过旷久的战争,ZMiG和707逐渐培养出了深厚的感♂情.他们逃到了另一块大陆上,决定远离世间的纷争,幸福地生活在一起.钟情707的neither_nor决心要把他们拆散,他要动用手中最大杀 ...
- 【NS2】How to remove Cygwin completely from Windows
How to remove Cygwin completely from Windows 9th September 2012. 31243 views. Software Remember need ...
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H Skiing【拓扑排序,关键路径】
2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 H Skiing In this winter holiday, Bob has a plan for skiing at the moun ...
- 2016 Asia Jakarta Regional Contest L - Tale of a Happy Man UVALive - 7722
UVALive - 7722 一定要自己做出来!
- iOS 设计
APP引导页设计经验分享 http://www.cocoachina.com/design/20150615/12126.html 获取app安装的进度,6种不同的加载指示 http://www.co ...
- @loj - 2090@ 「ZJOI2016」旅行者
目录 @description@ @solution@ @accepted code@ @details@ @description@ 小 Y 来到了一个新的城市旅行.她发现了这个城市的布局是网格状的 ...
- 交互式计算和开发环境:IPython
- Project Euler Problem 23-Non-abundant sums
直接暴力搞就行,优化的地方应该还是计算因子和那里,优化方法在这里:http://www.cnblogs.com/guoyongheng/p/7780345.html 这题真坑,能被写成两个相同盈数之和 ...