C版:
#include <stdio.h>
int main()
{
int a,b;
while(scanf("%d %d",&a, &b) != EOF)
printf("%d\n",a+b);
return 0;
}
C++版:
#include <iostream>
using namespace std;
int main()
{
int a,b;
while(cin >> a >> b)
cout << a+b << endl;
}
C++17 版:
#include <bits/stdc++.h>
using namespace std;
int main() {
while (true) {
if (int a, b; cin >> a >> b) {
cout << a + b << endl;
} else {
break;
}
}
}
C++20版:
#include <bits/stdc++.h>
using namespace std;
template<typename T>
concept Addable = requires (T obj) {{obj + obj} -> std::same_as<T>;};
template<Addable T>
T add(T a, T b) {
return a + b;
}
int main() {
while (true) {
if (int a, b; cin >> a >> b) {
cout << add(a, b) << endl;
} else {
break;
}
}
}
Java版:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int a = in.nextInt();
int b = in.nextInt();
System.out.println(a + b);
}
}
}
Pascal(FPC):
program p1000(Input,Output);
var
a,b:Integer;
begin
while not eof(Input) do
begin
Readln(a,b);
Writeln(a+b);
end;
end.
Python2/3版:
import sys
for line in sys.stdin:
a = line.split()
print(int(a[0]) + int(a[1]))
PHP版:
<?php
while (fscanf(STDIN, "%d%d", $a, $b) == 2) {
print ($a + $b) . "\n";
}
?>
C#版:
using System;
using System.Linq;
namespace ConsoleApp
{
public class Program
{
private static void Main()
{
string line;
while((line = Console.ReadLine()) != null)
{
Console.WriteLine(line.Split().Select(int.Parse).Sum());
}
}
}
}
Lua版:
local count = 0
function string.split(str, delimiter)
if str==nil or str=='' or delimiter==nil then
return nil
end
local result = {}
for match in (str..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match)
end
return result
end
while true do
local line = io.read()
if line == nil or line == "" then break end
local tb = string.split(line, " ")
local sum = 0
for i=1, #tb do
local a = tonumber(tb[i])
sum = sum+a
end
if count>0 then
io.write("\n")
end
io.write(string.format("%d", sum))
count = count+1
end
Perl版:
my $input;
while($input = <>){
chomp($input);
my @array = split ' ',$input;
print $array[0]+$array[1],"\n";
}
Bash 版:
while read a b; do
echo `expr ${a} + ${b}`
done
GO版:
package main import "fmt" import "io" func main() { var A, B int for { _, err := fmt.Scan(&A, &B) if err == io.EOF { break } fmt.Println(A+B) }
}