当前位置:网站首页>库函数--(持续更新)
库函数--(持续更新)
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);
边栏推荐
- 打开浏览器的同时会在主页外同时打开芒果TV,抖音等网站
- How to configure flymcu (STM32 serial port download software) is shown in super detail
- 误删Path变量解决
- Punctual atom stm32f103zet6 download serial port pin
- 02-项目实战之后台员工信息管理
- Remember the interview algorithm of a company: find the number of times a number appears in an ordered array
- MySQL主從複制、讀寫分離
- SSM integrated notes easy to understand version
- 牛客Novice月赛40
- Some notes of MySQL
猜你喜欢
Machine learning -- census data analysis
Redis的基础使用
引入了junit为什么还是用不了@Test注解
How to build a new project for keil5mdk (with super detailed drawings)
double转int精度丢失问题
csdn-Markdown编辑器
Asp access Shaoxing tourism graduation design website
QT creator runs the Valgrind tool on external applications
一键提取pdf中的表格
[ahoi2009]chess Chinese chess - combination number optimization shape pressure DP
随机推荐
Machine learning -- census data analysis
csdn-Markdown编辑器
There are three iPhone se 2022 models in the Eurasian Economic Commission database
[蓝桥杯2017初赛]方格分割
Number game
【博主推荐】C#MVC列表实现增删改查导入导出曲线功能(附源码)
学习问题1:127.0.0.1拒绝了我们的访问
Ansible practical Series II_ Getting started with Playbook
Asp access Shaoxing tourism graduation design website
Deoldify project problem - omp:error 15:initializing libiomp5md dll,but found libiomp5md. dll already initialized.
图像识别问题 — pytesseract.TesseractNotFoundError: tesseract is not installed or it‘s not in your path
數據庫高級學習筆記--SQL語句
Project practice - background employee information management (add, delete, modify, check, login and exit)
C语言读取BMP文件
MySQL master-slave replication, read-write separation
软件测试-面试题分享
Basic use of redis
机器学习笔记-Week02-卷积神经网络
MySQL other hosts cannot connect to the local database
vs2019 第一个MFC应用程序