A+B问题
来自维基百科,自由的百科全书
A+B问题是一个基础的程序设计问题。通常是信息学在线评测系统用来测试提交和输入输出方法的题目。[1]
一般描述
输入两个数和(一般是在整数范围内),输出的计算结果。
示例代码
import java.util.*;
public class AB {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a,b;
a=sc.nextInt();
b=sc.nextInt();
System.out.println(a+b);
} //main end
} //AB end
#include <stdio.h>
int main(void)
{
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a + b);
return 0;
}
#include <iostream>
int main()
{
int a, b;
std::cin >> a >> b;
std::cout << a + b << std::endl;
return 0;
}
或
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << endl;
return 0;
}
var a,b:longint;
begin
readln(a,b);
writeln(a+b)
end.
gets.strip.split.map(&:to_i).reduce(:+)
适用于 Python 3 :
print(sum(map(int, input().split())))
PROGRAM P1000
IMPLICIT NONE
INTEGER :: A, B
READ(*,*) A, B
WRITE(*, "(I0)") A + B
END PROGRAM P1000
<?php
$input = trim(file_get_contents("php://stdin"));
list($a, $b) = explode(' ', $input);
echo $a + $b;
扩展
有的版本会对命题的条件进行调整,增加或删除某些限制条件,使得以上示例代码无法通过测试,例如:
参考文献
参见
Wikiwand - on
Seamless Wikipedia browsing. On steroids.