【全排列】
头文件:
#include <algorithm>
用法:
do
{
}while(next_permutation(a+i,a+j));//将a+i到a+j的子串进行全排列
例:
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
char a[6]="abcde";
do
{
cout<<a<<endl;
}while(next_permutation(a+1,a+4));
return 0;
}
【字符转换成数字】
1.atoll
头文件:
#include <cstdlib>
用法:
long long a=atoll(const b)//将字符串b转换成长长整型的数a(b为字符串头指针)
例:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
char a[20]="123456789123456789";
long long b;
b=atoll(a);
cout<<b<<endl;
return 0;
}
其他类似函数:
atof(将字符串转换成浮点型数)
atoi(将字符串转换成整型数)
atol(将字符串转换成长整型数)
strtod(将字符串转换成浮点数)
strtol(将字符串转换成长整型数)
strtoul(将字符串转换成无符号长整型数)
toascii(将整型数转换成合法的ASCII 码字符)
toupper(将小写字母转换成大写字母)
tolower(将大写字母转换成小写字母)
atoi(将字符串转换成整型数)
atol(将字符串转换成长整型数)
strtod(将字符串转换成浮点数)
strtol(将字符串转换成长整型数)
strtoul(将字符串转换成无符号长整型数)
toascii(将整型数转换成合法的ASCII 码字符)
toupper(将小写字母转换成大写字母)
tolower(将大写字母转换成小写字母)
【#define #ifdef #endif 的简单用法】
#include <iostream>
#define debug
using namespace std;
void DEBUG()
{
#ifdef debug
cout<<"++++++++++"<<endl;
#endif
}
int main()
{
cout<<"----------"<<endl;
DEBUG();
return 0;
}
#include <iostream>
//#define debug //加了注释
using namespace std;
void DEBUG()
{
#ifdef debug
cout<<"++++++++++"<<endl;
#endif
}
int main()
{
cout<<"----------"<<endl;
DEBUG();
return 0;
}
【字符逆置】
头文件:#include <cstring>
例:
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str[10];
cin>>str;
strrev(str);
cout<<str<<endl;
return 0;
}