帮助
评测
C++ 使用g++ 9.4.0
编译,命令为g++ -fno-asm -Wall -lm --static -O2 -std=c++14 -DONLINE_JUDGE -o Main Main.cc
;
C 使用gcc 9.4.0
编译,命令为gcc Main.c -o Main -fno-asm -Wall -lm --static -O2 -std=c99 -DONLINE_JUDGE
您可以使用#pragma GCC optimize ("O0")
手工关闭 O2 优化;
Pascal 使用fpc 3.0.4
编译,命令为fpc Main.pas -oMain -O1 -Co -Cr -Ct -Ci
。
Java 使用OpenJDK 17.0.4
编译,命令为javac -J-Xms32m -J-Xmx256m Main.java
,如果您的代码中没有public class
,请将入口类命名为Main
,在评测时提供额外 2 秒的运行时间和 512MB 的运行内存。
Python 使用Python 3.10.6
运行环境,命令为python3 Main.py
。
这里给出的编译器版本仅供参考,请以实际编译器版本为准。
请使用标准输入输出。
Q: cin/cout为什么会超时(TLE)?
A: cin/cout因为默认同步stdin/stdout而变慢,并产生更多的系统调用而受到性能影响,可以在main函数开头加入下面代码加速:
ios::sync_with_stdio(false); cin.tie(0);
Q: gets函数没有了吗?
A: gets函数因为不能限制输入的长度,造成了历史上大量的缓冲区溢出漏洞,因此在最新版本中被彻底删除了,请使用fgets这个函数取代。 或者使用下面的宏定义来取代:
个人资料
本站不提供头像存储服务,而是使用 QQ 头像显示。请使用QQ邮箱注册 ,系统自动取用您在QQ的头像。
返回结果说明
试题的解答提交后由评分系统评出即时得分,每一次提交会判决结果会及时通知;系统可能的反馈信息包括:
程序样例
以下样例程序可用于解决这道简单的题目:读入2个整数A和B,然后输出它们的和。
gcc (.c)
#include int main(){ int a, b; while(scanf("%d %d",&a, &b) != EOF){ printf("%d\n", a + b); } return 0; }
g++ (.cpp)
#include using namespace std; int main(){ // io speed up const char endl = '\n'; std::ios::sync_with_stdio(false); cin.tie(nullptr); int a, b; while (cin >> a >> b){ cout << a+b << endl; } return 0; }
fpc (.pas)
var a, b: integer; begin while not eof(input) do begin readln(a, b); writeln(a + b); end; end.
javac (.java)
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int a = in.nextInt(); int b = in.nextInt(); System.out.println(a + b); } } }
python3 (.py)
import io import sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') for line in sys.stdin: a = line.split() print(int(a[0]) + int(a[1]))