5082: A+B Problem

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:2 解决:1

题目描述

输入两个自然数a,b,输出他们的和。

输入

共一行:两个自然数a和b,中间用一个空格隔开。

(0<=a,b<=32767)

输出

共一行:输出a+b。

样例输入 复制

123 500

样例输出 复制

623

提示

你的程序应该从标准输入stdin('Standard Input')获取输出 并将结果输出到标准输出stdout('Standard Output')。

例如,在C语言可以使用'scanf',在C++可以使用'cin'进行输入;在C使用'printf',在C++使用'cout'进行输出。

用户程序不允许直接读写文件,如果这样做可能会判为运行时错误"Runtime Error"。

下面是题号为1000的题目的参考答案:


C++:
 #include <iostream>
using namespace std;
int main() {
    int a,b;
    while (cin >> a >> b) {
        cout << a+b << endl;
    }
	return 0;
} 
C:
 #include <stdio.h>
int main() {
    int a,b;
    while (scanf("%d %d",&a, &b) != EOF) {
        printf("%d\n",a+b);
    }
	return 0;
} 
PASCAL:
 program p1001(Input,Output); 
var 
  a,b:Integer; 
begin 
   while not eof(Input) do 
     begin 
       Readln(a,b); 
       Writeln(a+b); 
     end; 
end. 
Java:
 import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		int a, b;
		while (cin.hasNext()) {
			a = cin.nextInt(); 
			b = cin.nextInt();
			System.out.println(a + b);
		}
	}
}

来源/分类