当前位置:网站首页>库函数--(持续更新)
库函数--(持续更新)
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);
边栏推荐
- How to set up voice recognition on the computer with shortcut keys
- 误删Path变量解决
- 连接MySQL数据库出现错误:2059 - authentication plugin ‘caching_sha2_password‘的解决方法
- MySQL与c语言连接(vs2019版)
- 打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
- 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
- Codeforces Round #771 (Div. 2)
- 记某公司面试算法题:查找一个有序数组某个数字出现的次数
- [蓝桥杯2017初赛]方格分割
- Image recognition - pyteseract TesseractNotFoundError: tesseract is not installed or it‘s not in your path
猜你喜欢
解决安装Failed building wheel for pillow
Basic use of redis
Swagger, Yapi interface management service_ SE
LeetCode #461 汉明距离
Install mongdb tutorial and redis tutorial under Windows
[Thesis Writing] how to write function description of jsp online examination system
Django running error: error loading mysqldb module solution
Software testing and quality learning notes 3 -- white box testing
PyCharm中无法调用numpy,报错ModuleNotFoundError: No module named ‘numpy‘
csdn-Markdown编辑器
随机推荐
Dotnet replaces asp Net core's underlying communication is the IPC Library of named pipes
报错解决 —— io.UnsupportedOperation: can‘t do nonzero end-relative seeks
Kept VRRP script, preemptive delay, VIP unicast details
使用lambda在循环中传参时,参数总为同一个值
[蓝桥杯2017初赛]包子凑数
Case analysis of data inconsistency caused by Pt OSC table change
ES6 Promise 对象
软件测试与质量学习笔记3--白盒测试
误删Path变量解决
Punctual atom stm32f103zet6 download serial port pin
Basic use of redis
Machine learning -- census data analysis
Pytorch基础
牛客Novice月赛40
Error reporting solution - io UnsupportedOperation: can‘t do nonzero end-relative seeks
Did you forget to register or load this tag
MySQL主从复制、读写分离
Learning question 1:127.0.0.1 refused our visit
项目实战-后台员工信息管理(增删改查登录与退出)
Request object and response object analysis