如何在 Ubuntu 上安装 LNMP 环境
使用断言函数 debug
杭电多校后标程里经常看见大神的代码里有断言函数,像这样:assert(a[1] == 1)
,便了解了一下断言函数。
形式:void assert (int expression);
头文件:assert.h
当括号内表达式为真时继续运行程序,为假时向系统的错误设备抛出一个错误,并退出程序。
例程:
#include <bits/stdc++.h>
using namespace std;
int main()
{
freopen("input.txt","r",stdin);
char a = 'N';
assert(a != 'N');
cout << a << endl;
cout << __FUNCTION__ << ", " << __LINE__ << endl;
return 0;
}
断言括号内的表达式为假,所以运行结果:
Assertion failed!
Program: C:\Users\syf\src\ACM\test.exe
File: C:\Users\syf\src\ACM\test.cpp, Line 8
Expression: a != 'N'
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
此时没有执行9、10行的语句。
大量断言函数会减缓程序运行速度,且断言函数仅在debug时有作用。
取消代码中所有断言时在#include <assert.h>
语句前加上宏定义#define NDEBUG
即可。
Sublime Text 编译 c++11
事情起源于一次比赛中大佬的标程无法用sublime直接编译,错误提示如下:
唔,原来是sublime自带的c++编译系统没有-std=c++11
的选项。
先看看自带的c++编译系统是怎么配置的。
已经完结的 ACM 模板
这是唯一一篇完全撕掉之前的文章,重新撰写的文章。
文章之前的标题是《不定时更新的 ACM 模板》
然鹅现在,完结啦!!!撒花!!!(???)
退役来,多的就不说了,模板打包成 PDF 保留。