当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1000:A+B problem

题目描述

Calculate a+b.

输入解释

Two integers a and b, there is more than one input.

输出解释

Output a + b.

输入样例 1
1 2
输出样例 1
3

输入样例 2
89 0
0 0
0 1
输出样例 2
89
0
1

提示
-2147483646 < a+b < 2147483647

下面是 1000题的参考答案

C++/Clang++:

#include <iostream>
using namespace std;
int main(){
    int a,b;
    while(cin >> a >> b)
        cout << a+b << endl;
 return 0;
} 

C/Clang:

#include <stdio.h>
int main(){
    int a,b;
    while(scanf("%d %d",&a, &b) != EOF)
        printf("%d\n",a+b);
 return 0;
} 

PASCAL:

program p1000(Input,Output); 
var 
  a, b: Longint; 
begin 
   while not eof(Input) do 
     begin 
       Readln(a, b); 
       Writeln(a + b); 
     end; 
end.

Java1.7:

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);
		}
	}
}

Python2.7/Python3.5:

import sys
for line in sys.stdin:
    a = line.split()
    print(int(a[0]) + int(a[1]))

Perl:

@str =<STDIN>;
foreach $line (@str)
{
 @arr = split(/\s/, $line);
 print (@arr[0] + @arr[1]."\n");
} 

JavaScript:

var readline = require('readline');

var  rl = readline.createInterface({
    input:process.stdin,
    output:process.stdout
});

rl.on("line",function(stdin){
    a = stdin.split(" ");
    if (! isNaN(parseInt(a[0]))) {
        console.log(parseInt(a[0]) + parseInt(a[1]));
    }
});

PHP:

<?php  
while(fscanf(STDIN, "%d %d", $a, $b) == 2) 
    echo ($a + $b)."\n";

C#:

using System;
class Acm
{
	static void Main()
	{
		string input;
		while((input= Console.ReadLine()) != null)
		{
			string[] ss;
			ss = input.Split();
			Console.WriteLine(long.Parse(ss[0]) + long.Parse(ss[1]));
		}
	}
}

GoLang:

package main

import (
	"fmt"
	"io"
)

var a, b int

func main() {
    for {
        _, err := fmt.Scanf("%d %d", &a, &b)
        if err == io.EOF {
            break
        }
        fmt.Printf("%d\n", a + b)
    }
}

该题目包含在题集 SSPU

题目来源 sspu

共提交 5609

通过率 60.37%
时间上限 内存上限
1000 MS 128 MB