1. getline(cin,str); string流
cin.getline(str,n,结束字符) 结束字符默认为'\0' istream流
2. A->a表示A是指向结构体的指针
A.a表示A是结构体
A->a等效于(*A).a
3. 变量的定义不允许使用连等式
int a=b=c=1; //变量的定义不允许使用连等式
变量的赋值允许使用连等式
int a,b,c;
a=b=c=1;//这是可以通过编译的,a,b,c的值都赋值为1
4. 比scanf省点事
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
5. new/delete是C++关键字,需要编译器支持。
malloc/free是库函数,需要头文件支持。
int* number = new int;
delete number;
int* arr = new int[100];
delete[] arr;
int* carr = (int*)malloc(100 * sizeof(int));
free(carr);
6. sscanf(str,"%d",&n) 把str的内容以"%d"的格式写入到n中(从左到右)
sprintf(str,"%d",n) 把n以"%d"的格式写入到str (从右到左)
7. 优先队列priority_queue
//升序队列
priority_queue <int,vector<int>,greater<int> > q;
//降序队列
priority_queue <int,vector<int>,less<int> >q;
priority_queue<int> a; //默认大顶堆
8. 加速加速
for(register int i=1; i<=n; i++)
#define endl '\n'
#define icc std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);