import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); while (in.hasNextInt()) { //注意while处理多个case int a = in.nextInt();
int b = in.nextInt();
System.out.println(a + b);
}
}
}
Python
import sys
try:
while True:
line = sys.stdin.readline().strip()
if line == '':
break
lines = line.split()
print int(lines[0]) + int(lines[1])
except:
pass
Python3
import sys
for line in sys.stdin:
a = line.split()
print(int(a[0]) + int(a[1]))
JavaScript(V8)
while(line=readline()){
var lines = line.split(' ');
var a = parseInt(lines[0]);
var b = parseInt(lines[1]);
print(a+b);
}
JavaScript(Node)
var readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', function(line){
var tokens = line.split(' ');
console.log(parseInt(tokens[0]) + parseInt(tokens[1]));
});
C#
public class Program {
public static void Main() {
string line;
while ((line = System.Console.ReadLine ()) != null) {// 注意,如果输入是多个测试用例,请通过while循环处理多个测试用例
string[] tokens = line.Split();
System.Console.WriteLine(int.Parse(tokens[0]) + int.Parse(tokens[1]));
}
}
}
Php
<?php
while(fscanf(STDIN, "%d %d", $a, $b) == 2)
echo ($a + $b)."\n";
Go
package main
import (
"fmt"
)
func main() {
a:=0
b:=0
for {
n, _ := fmt.Scan(&a,&b)
if n == 0 {
break
} else {
fmt.Printf("%d\n",a+b)
}
}
}
R语言
lines=readLines("stdin")
for(l in lines){
if(l == ""){
break;
}
ll = strsplit(l, " ")[[1]]
a=ll[1];
b=ll[2];
cat(as.numeric(a)+as.numeric(b));
cat('\n');
}
Ruby
a, b = gets.split(" ").map {|x| x.to_i}
puts (a + b)
Rust
fn main() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
let nums:Vec<&str>= input.trim().split(" ").collect();
let num1: i32 = nums[0].parse().unwrap();
let num2: i32 = nums[1].parse().unwrap();
let sum = num1 + num2;
println!("{}\n", sum);
}
Swift
import Foundation
while let line = readLine() {
let parts = line.split(separator: " ")
print(Int(parts[0])! + Int(parts[1])!)
}
ObjectC
#import <Foundation/Foundation.h>
int main(int argc,char * argv[])
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
int a,b;
while(scanf("%d %d",&a, &b) != EOF)
printf("%d\n",a+b);
[pool drain];
return 0;
}
Pascal
var i, j : integer;
begin
while not eof do
begin
readln(i, j);
writeln(i + j);
end;
end.
matlab
try
while 1
line = input('', 's');
lines = strsplit(line);
printf("%d\n", str2num(lines{1}) + str2num(lines{2}));
end
catch
end
Bash
#!/bin/bash
read -a arr
while [ ${#arr[@]} -eq 2 ]
do
sum=$((${arr[0]}+${arr[1]}))
echo $sum
read -a arr
done
exit 0
3. 判题系统状态
4. 开始练习吧
全部评论
(1022) 回帖