版权声明: https://blog.csdn.net/ysq96/article/details/82225640
做个小笔记,pat时注意
1.map、set的自动排序如何解决
- 使用 unordered_map,unordered_set,则无序
- 重载排序,修改排序的函数
bool operator < (const node &a)const{
return cnt!=a.cnt?cnt>a.cnt:num<a.num;
}
2.lower_bound()和upper_bound()
lower:返回第一个大于等于的位置
upper:返回第一个大于的位置
3.最大公约数和最小公倍数
最大公约数:
int gcd(int a,int b){
return !b?a:gcd(b,a%b);
}
最小公倍数:
int d=gcd(a,b);
a/d*b;
4.sscanf和ssprintf
#include<stdio.h>
sscanf(str,"%d",&n);//将str以“%d”的格式写到n中(从左至右)
sprintf(str,"%d",n)//将n以“%d”的格式写到str中(从右至左)