1.cout<<setw(n)中默认数据右对齐
若想形成左对齐 即 cout<<left<<setw(10)<<a<<endl;
2.错排公式:f(n)=(n-1)*[f(n-1)+f(n-2)]
3.数字字符-‘0’即为数字
string a="123";
int temp=a[0]-'0'; //temp=1
4.while使用应该先判断是否超过有效长度再判断值
while(i<len&&isdigit(m[i]))
注意 i<len 写在前
4.通过重载小于运算符来自定义排序 仅用于自定义结构体
例子:
bool operator <(string a,string b)
{
int temp1=a[1]+a[3];
int temp2=b[1]+b[3];
if(temp1>temp2) return true;
else return false;
}
也可以通过定义cmp函数来实现
bool cmp(string a,string b)
{
int temp1=a[1]+a[3];
int temp2=b[1]+b[3];
if(temp1<temp2) return true;
else return false;
}
两者判断情况相反
cmp函数
升序:
bool cmp(int a,int b)
{
if(a<b) return true;
else return false;
}
倒序:
bool cmp(int a,int b)
{
if(a>b) return true;
else return false;
}