Preparing NOJ

A+B Problem

0ms 0K

Description:

输入两个自然数,输出他们的和

Input:

两个自然数 x 和 y \((0 <= x, y <= 32767)\)

Output:

一个数,即 x 和 y 的和

Sample Input:

123 500

Sample Output:

623

Note:

各个测试点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)

Info

Vijos

Provider Vijos

Origin P1000 A+B Problem

Code VIJ1000

Tags

Submitted 100

Passed 67

AC Rate 67%

Date 07/21/2019 14:01:48

Related

Nothing Yet