由于本人只会 C++ ,所以以下所有皆以 C++ 为例
以下代码皆以题目 A+B 为例
Accept
Accept
表示通过,一般简称AC
,是所有竞赛选手最喜欢的情况
(我好能水)
代码
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b;
return 0;
}
Wrong Answer
Wrong Answer
为答案错误,说明代码中出现了炸心态的问题,需要修改
debug 技巧:printf 大法
代码
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b + 1;
return 0;
}
Compile Error
Compile Error
为编译错误,说明代码中有不合法语句,需根据提示进行修改
代码
#include <iostream>
using namespace std;
int main()
{
cin >> a >> b;
cout << a + b;
return 0;
}
Time Limit Exceeded
运行时间超限,有两种情况,
- 代码运行过程中出现了死循环,需要进行 debug
- 代码时间复杂度过高,无法在规定时间之内处理所有数据,需要优化
debug 技巧:删代码大法,printf 大法
代码
情况 1
#include <iostream>
using namespace std;
int main()
{
while (true);
return 0;
}
情况 2
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
int result = 0;
for (int i = 0; i < a << 1; i ++ )
result ++ ;
for (int i = 0; i < b << 1; i ++ )
result ++ ;
while (a -- ) result -- ;
while (b -- ) result -- ;
cout << result << endl;
return 0;
}
这题我能想出来 TLE 解法,也够不容易的了,来了就给个赞吧
Memory Limit Exceeded
运行空间超限,同样有二种情况,
- 代码运行过程中出现了无终止递归,需要进行 debug
- 数组过大
debug 技巧:删代码大法,printf 大法
代码
情况 1
#include <iostream>
using namespace std;
int main()
{
main();
return 0;
}
情况 2
#include <iostream>
using namespace std;
int a, b;
int result;
void add(int a, int b)
{
if(a && b)
{
result ++ ;
add(a - 1, b);
}
else if (b)
{
result ++ ;
add(a, b - 1);
}
}
int main()
{
cin >> a >> b;
add(a, b);
cout << result << endl;
return 0;
}
如果刚才还没有点赞的话,看在我连 MLE 的解法都能想出来的份上,就给个赞吧
Output Limit Exceeded
输出超限,一般是由于死循环或无终止递归中的输出引起
debug 技巧:删代码大法
代码
#include <iostream>
using namespace std;
int main()
{
while (true)
putchar('~');
return 0;
}
Segmentation Fault
段错误,这个错误原因就比较复杂了。
段错误是指访问的内存超过了系统所给这个程序的内存空间,通常这个值是由 gdtr 来保存的,他是一个 48 位的寄存器,其中的 32 位是保存由它指向的 gdt 表,后 13 位保存相应于 gdt 的下标,最后 3 位包括了程序是否在内存中以及程序的在 cpu 中的运行级别,指向的 gdt 是由以 64 位为一个单位的表,在这张表中就保存着程序运行的代码段以及数据段的起始地址以及相应的断限和页面交换还有程序运行级别和内存粒度等信息,一旦一个程序发生了越界访问,CPU 就会产生相应的异常保护,于是可恨的 Segmentation Fault 就出现了。
段错误的情况较为复杂
- 访问类型错误
- 访问了不属于进程地址空间的内存
- 访问了不存在的内存
- 内存越界,数组越界,变量类型不一致等
- 试图把一个整数按照字符串的方式输出
debug 技巧:删代码大法
代码
情况 1;访问类型错误
#include <iostream>
using namespace std;
int main()
{
char* c = "Segmentation Fault";
c[0] = 'a';
return 0;
}
情况 2;访问了不属于进程地址空间的内存
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int a, b;
scanf("%d %d", a, b);
printf("%d", a + b);
return 0;
}
情况 2;访问了不存在的内存
#include <iostream>
using namespace std;
int main()
{
int* p = NULL;
*p = 1;
return 0;
}
情况 3;内存越界,数组越界,变量类型不一致
#include <iostream>
using namespace std;
const int N = 10;
int a[N];
int main()
{
cout << a[11] << endl;
return 0;
}
情况 5;把一个整数按照字符串的方式输出
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int a;
int main()
{
printf("%s\n", a);
return 0;
}
Float Point Exception
浮点数异常,通常是程序运行中出现了整形数字
除以 0 的情况
#include <iostream>
using namespace std;
int main()
{
int a = 1;
cout << a / 0;
return 0;
}
Non Zero Exit Code
非零退出,C++ 中一般不会遇到
debug 方法:检查主函数是否 return 0;
#include <iostream>
using namespace std;
int main()
{
return 1;
}
Runtime Error
数组开太大了
#include <iostream>
using namespace std;
int orz[300000010];
int main()
{
return 0;
}
Presentation Error
输出格式不对,一般是多输出回车或少输出空格了
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << endl << endl;
return 0;
}
按理说应该还有 PC 和 UKE 的,但是目前从未遇到过
若有不足,还请大佬及时在评论区反馈给我,我会尽快进行修改
终于水完了
NonZeroExitCode
有人问怎么回事来看下(C++的)
佬,我也C++,想问一下,数据太多导致用例显示不完全找不到错误用例咋办,我都拉了个表格一个个对照了,然后发现错误的没显示出来
java怎么提交?
Main.java:4: error: class Demo is public, should be declared in a file named Demo.java
public class Demo {
^
大佬,SF的数字顺序打错了
你写的是12235
抽风大佬!
html
$\color{rgb(444,444,444)}{html}
有html那味了
Accept
hh
hh
红色的
没有除以0但是Float point exception啥情况呢
Orz
UKE很多时候是测评器的问题呐
Internal Error 这个是啥?没初始化?
可能是网不好?
记得还有个PE错误类型~~
谢谢大佬提醒,已经补上了
客气啥,给我康康你的女装就行啦hh
tql 雪中送炭 爱你baby
。。。
%%%%%%
qwq
您也会Python。。。