- 结构题内部筛+优先队列
struct node{
char a;
int rank;
friend bool operator<(node a,node b) {
return a.rank>b.rank;
}
};
priority_queue<node>q;
- 读有空格以换行符结束的字符串
scanf("%[^\n]",a);(或者scanf("%[^\n]s",a);)
https://blog.csdn.net/jeffasd/article/details/80705487 //这他妈黑科技把!!!我服了QAQ
或
int pos=0;
while(~scanf("%c",&a[pos])) {
pos++;
if(a[pos-1]=='\n') {
pos--;break;
}
}
- string可以用cin读cout输出
-
%f 表示按浮点数的格式输出
%e 表示按指数形式的浮点数的格式输出
%g 表示自动选择合适的表示法输出
eg:
#include<cstdio>
using namespace std;
int main()
{
float f = 111.111;
printf("%f\n", f); // 输出111.111000
printf("%e\n", f); // 输出1.111110e+002
printf("%g\n", f); // 输出111.111
}
- %c 一个单一的字符
%d 一个十进制整数
%i 一个整数
%o 一个八进制数
%s 一个字符串
%x 一个十六进制数
%p 一个指针
%n 一个等于读取字符数量的整数
%u 一个无符号整数
%[] 一个字符集
%% 一个精度符号 - 输入流
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
- lower_bound() && upper_bound()
lower_bound(a,a+n,b)-a;
从从小到大排好序的数组a的begin位置到end-1位置二分查找第一个大于或等于b的数字,找到返回该数字的地址,不存在则返回end。通过返回的地址减去起始地址begin,得到找到数字在数组中的下标。
从大到小的数组需要对lower_bound()进行重载:lower_bound( begin,end,num,greater<type>() )
- 输入输出文件
freopen("input.txt", "r", stdin);
//只改变输入流的文件指针,读入这个文件的内容(必须要有input这个文件)stdin是标准输入流的文件指针
freopen("output.txt", "w", stdout);
//只改变输出流的文件指针,写入output内(如果没有output这个文件就会自动生成)stdout是标准输出流的文件指针
- 用异或来完成交换过程
a^=b;
b^=a;
a^=b;
- fflush用于清空缓冲流,虽然一般感觉不到,但是默认printf是缓冲输出的。
fflush(stdin);//注意只适用于部分编译器,是对c标准的扩充