当前位置:网站首页>库函数--(持续更新)
库函数--(持续更新)
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);
边栏推荐
- AcWing 1298. Solution to Cao Chong's pig raising problem
- Install mysql5.5 and mysql8.0 under windows at the same time
- [Thesis Writing] how to write function description of jsp online examination system
- MySQL other hosts cannot connect to the local database
- 连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
- Ansible实战系列三 _ task常用命令
- What does usart1 mean
- Ansible practical Series III_ Task common commands
- Request object and response object analysis
- 引入了junit为什么还是用不了@Test注解
猜你喜欢

error C4996: ‘strcpy‘: This function or variable may be unsafe. Consider using strcpy_s instead

Deoldify项目问题——OMP:Error#15:Initializing libiomp5md.dll,but found libiomp5md.dll already initialized.

In the era of DFI dividends, can TGP become a new benchmark for future DFI?
![[recommended by bloggers] C # generate a good-looking QR code (with source code)](/img/5a/1dbafe5a28f016b815964b9b37c9f1.jpg)
[recommended by bloggers] C # generate a good-looking QR code (with source code)
![[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)](/img/b7/aae35f049ba659326536904ab089cb.png)
[recommended by bloggers] C MVC list realizes the function of adding, deleting, modifying, checking, importing and exporting curves (with source code)

自动机器学习框架介绍与使用(flaml、h2o)

Solve the problem of installing failed building wheel for pilot

QT creator custom build process

Why can't I use the @test annotation after introducing JUnit

QT creator design user interface
随机推荐
LeetCode #461 汉明距离
数数字游戏
Cookie setting three-day secret free login (run tutorial)
Learn winpwn (3) -- sEH from scratch
QT creator support platform
MySQL other hosts cannot connect to the local database
L2-006 树的遍历 (25 分)
Are you monitored by the company for sending resumes and logging in to job search websites? Deeply convinced that the product of "behavior awareness system ba" has not been retrieved on the official w
[蓝桥杯2020初赛] 平面切分
Did you forget to register or load this tag 报错解决方法
double转int精度丢失问题
csdn-Markdown编辑器
C语言读取BMP文件
Ansible实战系列三 _ task常用命令
QT creator uses Valgrind code analysis tool
SSM integrated notes easy to understand version
AI benchmark V5 ranking
FRP intranet penetration
Test objects involved in safety test
Ubuntu 20.04 安装 MySQL