A+B Problem
背景
for beginners,特设此题,^_^
描述
输入两个自然数,输出他们的和
格式
输入格式
两个自然数 x 和 y \((0 <= x, y <= 32767)\)
输出格式
一个数,即 x 和 y 的和
样例1
样例输入1
123 500
样例输出1
623
限制
各个测试点1s,16MiB内存空间。
提示
本题测试数据下载:下载
Free Pascal Code
var a, b:longint;
begin
readln(a, b);
writeln(a + b);
end.
C Code
#include <stdio.h>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d\n", a + b);
}
C++ Code
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << endl;
}
C# Code
using System;
using System.Linq;
class Program {
public static void Main(string[] args) {
Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).Sum());
}
}
Python Code
print sum(map(int, raw_input().split()))
Python 3 Code
print(sum(map(int, input().split())))
Java Code
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(a + b);
}
}
PHP Code
<?php
fscanf(STDIN, "%d %d\n", $a, $b);
echo ($a + $b) . "\n";
Rust Code
use std::io;
fn main() {
let mut line = String::new();
io::stdin().read_line(&mut line).expect("stdin");
let sum: i32 = line.split_whitespace()
.map(|x| x.parse::<i32>().expect("integer"))
.sum();
println!("{}", sum);
}
Haskell Code
main = print . sum . map read . words =<< getLine
Javascript Code
const [a, b] = readline().split(' ').map(n => parseInt(n, 10));
print((a + b).toString());
Go Code
package main
import "fmt"
func main() {
var a, b int
fmt.Scanf("%d%d", &a, &b)
fmt.Printf("%d\n", a + b)
}
Ruby Code
a, b = gets.split.map(&:to_i)
puts(a + b)
信息
- ID
- 1000
- 难度
- 9
- 分类
- (无)
- 标签
- (无)
- 递交数
- 74304
- 已通过
- 28428
- 通过率
- 38%
- 被复制
- 216