C

```/* A + B Problem in C */
#include <stdio.h>

int main(void) {
int a, b;

while (scanf("%d%d", &a, &b) != EOF) {
printf("%d\n", a + b);
}

return 0;
}
```

C++

```// A + B Problem in C++
#include <iostream>

int main() {
int a, b;

while (std::cin >> a >> b) {
std::cout << a + b << std::endl;
}

return 0;
}
```

Python

```#!/usr/bin/python
# A + B Problem in Python

import sys

for line in sys.stdin:
print sum(map(int, line.split()))
```

Ruby

```#!/usr/bin/ruby
# A + B Problem in Ruby

readlines.each{|line|
p line.split.collect{|x| x.to_i}.inject{|y, x| y += x}
}
```

C#

```// A + B Problem in C#
using System;

public class EMP {
public static void Main(string[] args) {
String input;
while ((input = Console.ReadLine()) != null) {
String[] inputs = input.Split();
int n = Int32.Parse(inputs[0]), m = Int32.Parse(inputs[1]);
Console.WriteLine(n + m);
}
}
}
```

Java

```// A + B Problem in Java
import java.io.*;

public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line = null;
while ((line = in.readLine()) != null) {
String[] ab = line.split(" ");
System.out.println(Integer.parseInt(ab[0]) + Integer.parseInt(ab[1]));
}
}
}
```

Pascal

```{A + B Problem in pascal}
program gao(input, output);

var
n, m: integer;

begin
while not eof(input) do
begin
readln(n, m);
writeln(n + m);
end;
end.
```

php

```#!/usr/bin/php
<?
// A + B Problem in php
while (fscanf(STDIN, "%d%d", \$a, \$b) == 2) {
echo \$a + \$b, "\n";
}
?>
```

perl

```#!/usr/bin/perl -pla
# A + B Problem in perl
\$_=\$F[0]+\$F[1]
```
7 Responses to “A + B Problem”
1. quark says:

main = interact \$ unlines . map (show . sum . map read . words) . lines 有没有别的写法？
ocaml 貌似要处理 EOF 异常怎么写都长

• yzyzsun says:

Ruby 代码对 inject 方法的理解似乎有点问题：是每轮迭代的返回值，而不是 `y` 的终值，作为下一轮的 `y`，所以没必要 `y += x`，只需 `y + x` 就行了。

• watashi says:

```line.split.map(&:to_i).inject(&:+)
```
2. fookwood says:

请教一下怎样使鼠标移到代码上右上角会出现.”view source”,”copy to clipboard”等图标…

• watashi says:

我这里用的是SyntaxHighlighter2

3. quark says:

果然我用的是GeShi，不过转义是我最关心的问题，许多插件在HTML文本模式下编辑勉强可以，一旦切换到所见即所得再保存一下就悲剧了 T_T
虽然目前用的WP-Syntax在大部分情况还比较不错，但是在#include的处理上总是悲剧 -.-

• watashi says:

不如自己处理转义，然后设置noescap还是叫什么的参数？

4.