当前位置:网站首页>库函数--(持续更新)
库函数--(持续更新)
2022-07-06 09:14:00 【%xiao Q】
isdigit():判断输入的字符有是否有数字组成
char ch;
isdigit(ch)
随机函数
srand((unsinged)(time(0))); // 随机种子
int x = rand() % 100 // 0 ~ 100的数
二分函数
// 返回大于val的值的地址
upper_bound(a.begin(), a.end(), val);
upper_bound(a, a + n, val, val);
// 返回大于等于val的值的地址
upper_lower(a.begin(), a.end(), val);
upper_lower(a, a + n, val);
整数变字符串
int num;
string s = to_string(nmu);
复制函数(把一个数组复制到另一个数组)
// vector<>容器的交换
vector<int> a, b;
a.assign(b.begin(), b.end()); // 把b复制给a
// a[]数组的交换
int a[N], b[N];
memcpy(a, b, sizeof b); // 把b复制给a
sqrt() 和 log() 函数的返回值为浮点型
全排列函数
// n为a数组长度
next_permutataion(a, a + n) // 升序的下一个,即 1 2 3 -> 1 3 2 -> 2 1 3 ... , 3 2 1 ,并且下一个如果存在返回1,否则返回0
prev_permutation(a, a + n) //降序的下一个,即 3 2 1 -> 3 1 2 ... 1 2 3,并且下一个如果存在返回1,否则返回0
子序列和子串
子串:连续的
子序列:可以不连续
小根堆和大根堆的定义
priority_queue<int> q; //大根堆
priority_queue<int, vector<int>, greater<int>> q; //小根堆
sort的从大到小的排序(2种方法)
int a[N];
sort(a, a + n, greater<int>()) //尖括号里的根据数组类型来定义
bool cmp(int x, y)
{
return x >= y;
}
int main()
{
int a[N];
sort(a, a + n, cmp);
}
全排列函数(c++)
int a[N];
do
{
...
}next_permutation(a, a + n); //实现升序
do
{
...
}prev_permutation(a, a + n) //实现降序
二分函数
- lower_bound():返回大于等于x的数组下标的地址
- upper_bound():返回大于x的数组下标的地址
如果这种数在数组中不存在,那么会返回数组长度。
int t = lower_bound(a, a + n, x) - a; //因为返回的是地址,所以要-a,即减去数组名
int t = upper_bound(a, a + n, x);
边栏推荐
- [蓝桥杯2021初赛] 砝码称重
- Windows下安装MongDB教程、Redis教程
- Why can't STM32 download the program
- neo4j安装教程
- Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.
- JDBC原理
- UDS learning notes on fault codes (0x19 and 0x14 services)
- 引入了junit为什么还是用不了@Test注解
- Learning question 1:127.0.0.1 refused our visit
- [AGC009D]Uninity
猜你喜欢
Windows下安装MongDB教程、Redis教程
软件测试与质量学习笔记3--白盒测试
vs2019 第一个MFC应用程序
Install mysql5.5 and mysql8.0 under windows at the same time
AcWing 242. A simple integer problem (tree array + difference)
Request object and response object analysis
【博主推荐】C#MVC列表实现增删改查导入导出曲线功能(附源码)
02-项目实战之后台员工信息管理
【博主推荐】SSM框架的后台管理系统(附源码)
Data dictionary in C #
随机推荐
Record a problem of raspberry pie DNS resolution failure
Why can't I use the @test annotation after introducing JUnit
LeetCode #461 汉明距离
QT creator shape
Rhcsa certification exam exercise (configured on the first host)
PyCharm中无法调用numpy,报错ModuleNotFoundError: No module named ‘numpy‘
How to set up voice recognition on the computer with shortcut keys
How to configure flymcu (STM32 serial port download software) is shown in super detail
Install mongdb tutorial and redis tutorial under Windows
What does BSP mean
error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead
How to build a new project for keil5mdk (with super detailed drawings)
數據庫高級學習筆記--SQL語句
vs2019 使用向导生成一个MFC应用程序
一键提取pdf中的表格
MySQL completely uninstalled (windows, MAC, Linux)
What does usart1 mean
Pytorch基础
安全测试涉及的测试对象
Request object and response object analysis