/**1******************************
int :-10^9~~~10^9
long long :-10^18~~~10^18
float和double的范围不理解,直接用double
/**2****************************
void swap(int a,int b)//交换a,b
/****3***************************
b = sizeof(a);//b为a所占的字节数
strlen(a)//获得字符型a的长度,a必须为字符指针
/*****4*************************************************************
c++中的快排
bool compare(int a,int b)//大到小排序
{
return a>b;
}
sort(数组起始地址,数组末地址,排序方法)
例
a[n]
sort(a+s,a+n,compare)//降排序,无compare则为升
其中,a+n代表a[n-1],a+s代表a[s+1],对a[s+1]到a[n-1]排序,包括a[s+1],a[n-1]
/******5*************************************************
string s;
s可以当成一个数组
/**************6****************************************
stack <char>s//定义一个char型的栈s
/************************************
int a[20]={0};//会自动把其余赋值为0
/*********************************
c++5.4.0中min(a,b),max(a,b)返回最大值或最小值
/********************************
int we(int n)//求十进制位数
{
int i = 0;
while(n!=0)
{
i++;
n = n/10;//把10换成2,就是求二进制位数了 ,也可以进制转换
}
return i;
}
void we(int n)
{
while(n!=0)
{
cout<<n%2;//反过来打印
n = n/2;//进制转换
}
}
/******************************
有关打印图形的,找到规律,注意与i,j的关系
/********************
void check(int i)//判断i是否为回文数,是则输出
{ int n = i;
int judge;
int New_n = 0;
while(i!=0)
{
judge = i %10;
New_n = New_n*10 + judge;
i = i/10;
}
if(New_n == n)
{
cout<<New_n<<endl;
}
}
/************************
bool check(int n)
{ if(n <= 1) return false;//0,1不是质数也不是合数,因式分解时,1当为质数
if(n == 2 || n == 3) return true;
if(n %6 != 1 &&n %6 != 5)return false;
for(int i = 5;i<=sqrt(n);i+=6)
{
if(n % i ==0 || n %(i+2)==0)//5,7
return false;
}
return true;
}
/************************
int gcd(int m, int n) //快速求最大公因数
{
while(m>0)
{
int c = n % m;
n = m;
m = c;
}
return n;
}
/**********************
memcmp(), memcpy(), and memmove().memset()
/******************************
next_permutation:求下一个排列组合
a.函数模板:
next_permutation(arr, arr+size);
b.参数说明:
arr: 数组名
size:数组元素个数
c.函数功能: 返回值为bool类型,当当前序列不存在下一个排列时,函数返回false,否则返回true,排列好的数在数组中存储
d.注意:在使用前需要对欲排列数组按升序排序,否则只能找出该序列之后的全排列数。
比如,如果数组num初始化为2,3,1,那么输出就变为了:{2 3 1} {3 1 2} {3 2 1}