PAT日记
1.如果有多个需要排序
bool cmp1(s s1,s s2)
{
return s1.score == s2.score ? s1.id < s2.id : s1.score > s2.score;
}
2.string的erase删除方法
string str = "hello c++! +++";
// 删除"+++"前的一个空格
str.erase(str.begin()+10);
cout << '-' << str << '-' << endl;
// 删除"+++"
str.erase(str.begin() + 10, str.end());
cout << '-' << str << '-' << endl;
return 0;
3.后续和中序找到一棵树的方法
int getTree(int inl,int inr,int postl,int postr)
{
if(inr < inl || postl > postr) return -1;
int root = post[postr];
int i;
for(i = inl;i <= inr;i++)
{
if(root == in[i])
{
break;
}
}
node[root].left = getTree(inl,i-1,postl,postl+i-inl-1);
node[root].right = getTree(i+1,inr,postl+(i-inl),postr-1);
return root;
}