版本比较
复赛笔记(有问题请私信)
正文
增加 25 行删除 25 行
12345616 行未改动2324252627282930313233343536373839406 行未改动4748495051525354558 行未改动6465666768697071723 行未改动767778798081828384852 行未改动8889909192939495969798991001012 行未改动104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166```cpp//一、常用函数。//1.swap()交换两个变量的值#include <algorithm>using namespace std;16 行未改动#include <algorithm>#include <vector>using namespace std;vector<int> vec(10);int main(){fill(vec.begin(),vec.end(),5);}//vec的所有元素为5//4.atoi()将C风格字符串转化为整数#include <cstdlib>using namespace std;const char* str="12345";int main(){int num=atoi(str);}//num=12345//5.stoi()将string转化为整数#include <string>using namespace std;string s="12345";int main(){int num=stoi(s);}//num=123456 行未改动//7.lower_bound()与upper_bound//lower_bound:在有序范围内查找一个不小于给定值的元素//upper_bound:在有序范围内查找一个大于给定值的元素//基于二分查找实现#include <algorithm>#include <vector>using namespace std;vector<int> vec={1,2,4,4,5,6};8 行未改动}//8.reverse()反转指定范围内的元素顺序#include <algorithm>#include <vector>vector<int> vec={1,2,3,4,5};int main(){reverse(vec.begin(),vec.end());}//vec变为{5,4,3,2,1}#include <algorithm>3 行未改动int main(){reverse(s.begin(),s.end());}//s变为"olleh"//9.sort()对数组、vector、list进行排序#include <algorithm>#include <vector>#include <iostream>using namespace std;int main(){vector<int> vec={4,2,3,5,1};2 行未改动{cout<<num<<" ";}return 0;//输出:1 2 3 4 5}#include <algorithm>#include <vector>#include <iostream>using namespace std;int main(){vector<int> vec={4,2,3,5,1};2 行未改动{cout<<num<<" ";}return 0;//输出:5 4 3 2 1}//二、数据结构。//1.list//底层:双向链表//插入:push_back(),push_front(),irser()//删除:pop_back(),pop_front(),erase(),femove()//查找:find()(需要配合<algorithm>库)//清空:clear()//判断空:empty()//遍历:使用迭代器begin()到end()//2.vector//底层:动态数组//插入:push_back(),insert()//删除:pop_back(),erase(),clear()//查找:find()(需要配合<algorithm>库)//清空:clear()//判断空:empty()//遍历:使用迭代器begin()到end()//3.stack//底层:栈//插入:push()//删除:pop()//访问栈顶:top()//判断是否为空:empty()//大小:size()//4.queue//底层:deque(双端队列)//插入:push()//删除:pop()//访问队首:front()//判断是否为空:empty()//大小:size()//5.priority_queue//底层:堆(默认最大堆)//插入:push()//删除:pop()//访问最大元素:top()//判断是否为空:empty()//大小:size()//6.map/multimap//底层:红黑树//插入:insert(),operator[]//删除:erase(),clear()//查找:find()//判断是否存在:使用find()返回的迭代器//清空:clear()//判断空:empty()//统计元素个数:count()(map只返回0或1)//遍历:使用迭代器 begin()到end()```更新中......12345616 行未改动2324252627282930313233343536373839406 行未改动4748495051525354558 行未改动6465666768697071723 行未改动767778798081828384852 行未改动8889909192939495969798991001012 行未改动104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166```cpp//一、常用函数。//1.swap()交换两个变量的值#include <algorithm>using namespace std;16 行未改动#include <algorithm>#include <vector>using namespace std;vector<int> vec(10);int main(){fill(vec.begin(),vec.end(),5);}//vec的所有元素为5//4.atoi()将C风格字符串转化为整数#include <cstdlib>using namespace std;const char* str="12345";int main(){int num=atoi(str);}//num=12345//5.stoi()将string转化为整数#include <string>using namespace std;string s="12345";int main(){int num=stoi(s);}//num=123456 行未改动//7.lower_bound()与upper_bound//lower_bound:在有序范围内查找一个不小于给定值的元素//upper_bound:在有序范围内查找一个大于给定值的元素//基于二分查找实现#include <algorithm>#include <vector>using namespace std;vector<int> vec={1,2,4,4,5,6};8 行未改动}//8.reverse()反转指定范围内的元素顺序#include <algorithm>#include <vector>vector<int> vec={1,2,3,4,5};int main(){reverse(vec.begin(),vec.end());}//vec变为{5,4,3,2,1}#include <algorithm>3 行未改动int main(){reverse(s.begin(),s.end());}//s变为"olleh"//9.sort()对数组、vector、list进行排序#include <algorithm>#include <vector>#include <iostream>using namespace std;int main(){vector<int> vec={4,2,3,5,1};2 行未改动{cout<<num<<" ";}return 0;//输出:1 2 3 4 5}#include <algorithm>#include <vector>#include <iostream>using namespace std;int main(){vector<int> vec={4,2,3,5,1};2 行未改动{cout<<num<<" ";}return 0;//输出:5 4 3 2 1}//二、数据结构。//1.list//底层:双向链表//插入:push_back(),push_front(),irser()//删除:pop_back(),pop_front(),erase(),femove()//查找:find()(需要配合<algorithm>库)//清空:clear()//判断空:empty()//遍历:使用迭代器begin()到end()//2.vector//底层:动态数组//插入:push_back(),insert()//删除:pop_back(),erase(),clear()//查找:find()(需要配合<algorithm>库)//清空:clear()//判断空:empty()//遍历:使用迭代器begin()到end()//3.stack//底层:栈//插入:push()//删除:pop()//访问栈顶:top()//判断是否为空:empty()//大小:size()//4.queue//底层:deque(双端队列)//插入:push()//删除:pop()//访问队首:front()//判断是否为空:empty()//大小:size()//5.priority_queue//底层:堆(默认最大堆)//插入:push()//删除:pop()//访问最大元素:top()//判断是否为空:empty()//大小:size()//6.map/multimap//底层:红黑树//插入:insert(),operator[]//删除:erase(),clear()//查找:find()//判断是否存在:使用find()返回的迭代器//清空:clear()//判断空:empty()//统计元素个数:count()(map只返回0或1)//遍历:使用迭代器 begin()到end()```更新中......