——< climits >头文件
climits中的符号常量
| 符号常量 | 表示 |
|---|---|
| CHAR_BIT | char的位数 |
| CHAR_MAX | char的最大值 |
| CHAR_MIN | char的最小值 |
| SCHAR_MAX | signed char的最大值 |
| SCHAR_MIN | signed char的最小值 |
| UCHAR_MAX | unsigned char的最大值 |
| UCHAR_MIN | unsigned char的最小值 |
| SHRT_MAX | short 的最大值 |
| SHRT_MIN | short的最小值 |
| USHRT_MAX | unsigned char的最大值 |
| INT_MAX | int的最大值 |
| INT_MIN | int的最小值 |
| UINT_MAX | unsigned int的最大值 |
| UINT_MIN | unsigned int的最小值 |
| LONG_MAX | long 的最大值 |
| LONG_MIN | long的最小值 |
| ULONG_MAX | unsigned long的最大值 |
| ULONG_MIN | unsigned long的最小值 |
| LLONG_MAX | long long的最大值 |
| LLONG_MIN | long long的最小值 |
| ULLONG_MAX | unsigned long long的最大值 |
——< algorithm >头文件
algorithm头文件下常用函数:
1) max( )
返回x和y中的最大值,且参数必须是两个
2) min( )
返回x和y中的最小值,且参数必须是两个
3) abs( )
abs(x) 返回x的绝对值。x必须为整数。浮点型的绝对值要用math头文件下的fabs
4) swap( )
swap(x,y)用来交换x和y的值
5) reverse( )
reverse(it,it2) 可以将数组指针在[it,it2)之间的元素 或 容器的迭代器在[it,it2)范围内的元素进行反转。
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int a[10]={10,11,12,13,14,15};
reverse(a,a+4);
for(int i=0;i<6;i++){
printf("%d ",a[i]);
}
return 0;
}
#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string str="abcdefghi";
reverse(str.begin()+2,str.begin()+6);
for(int i=0;i<str.length();i++){
printf("%c",str[i]);
}
return 0;
}
6) next_permutation( )
next_permutation() 给出一个序列在全排列中的下一个序列
#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int a[10]={1,2,3};
do{
printf("%d %d %d\n",a[0],a[1],a[2]);
}while(next_permutation(a,a+3));
return 0;
}
7) fill( )
fill() 可以把数组或容器中的某一段区间赋为某个相同的值。和memset不同,这里的赋值可以 使数组类型对应范围中 的任意值。
#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int a[10]={1,2,3,4,5};
fill(a,a+5,233);
for(int i=0;i<5;i++){
printf("%d ",a[i]);
}
return 0;
}
6) sort( )
默认为递增排序
* 若要递减排序,需要增加比较函数
bool cmp(int a,int b){
return a>b;
}
sort(a,a+n,cmp); 
京公网安备 11010502036488号