当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。
Calculate a+b.
Two integers a and b, there is more than one input.
Output a + b.
1 2
3
89 0 0 0 0 1
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) } }
时间上限 | 内存上限 |
1000 MS | 128 MB |