1 条题解

  • 1
    @ 2024-5-11 22:31:03

    本题各种语言的程序范例:

    C

    #include <stdio.h>
    
    int main()
    {
        int a,b;
        scanf("%d%d",&a,&b);
        printf("%d\n", a+b);
        return 0;
    }
    

    C++

    #include <iostream>
    #include <cstdio>
    
    using namespace std;
    
    int main()
    {
        int a,b;
        cin >> a >> b;
        cout << a+b << endl;
        return 0;
    }
    

    Pascal

    var a, b: longint;
    begin
        readln(a,b);
        writeln(a+b);
    end.
    

    Python2

    s = raw_input().split()
    print int(s[0]) + int(s[1])
    

    Python3

    s = input().split()
    print(int(s[0]) + int(s[1]))
    

    Java

    import java.io.*;
    import java.util.*;
    public class Main {
        public static void main(String args[]) throws Exception {
            Scanner cin=new Scanner(System.in);
            int a = cin.nextInt(), b = cin.nextInt();
            System.out.println(a+b);
        }
    }
    

    JavaScript (Node.js)

    const fs = require('fs')
    const data = fs.readFileSync('/dev/stdin')
    const result = data.toString('ascii').trim().split(' ').map(x => parseInt(x)).reduce((a, b) => a + b, 0)
    console.log(result)
    process.exit() // 请注意必须在出口点处加入此行
    

    Ruby

    a, b = gets.split.map(&:to_i)
    print a+b
    

    PHP

    <?php
    $input = trim(file_get_contents("php://stdin"));
    list($a, $b) = explode(' ', $input);
    echo $a + $b;
    

    Rust

    use std::io;
    
    fn main(){
        let mut input=String::new();
        io::stdin().read_line(&mut input).unwrap();
        let mut s=input.trim().split(' ');
    
        let a:i32=s.next().unwrap()
                   .parse().unwrap();
        let b:i32=s.next().unwrap()
                   .parse().unwrap();
        println!("{}",a+b);
    }
    

    Go

    package main
    
    import "fmt"
    
    func main() {
        var a, b int
        fmt.Scanf("%d%d", &a, &b)
        fmt.Println(a+b)
    }
    

    C# Mono

    using System;
    
    public class APlusB{
        private static void Main(){
            string[] input = Console.ReadLine().Split(' ');
            Console.WriteLine(int.Parse(input[0]) + int.Parse(input[1]));
        }
    }
    

    Visual Basic Mono

    Imports System
    
    Module APlusB
        Sub Main()
            Dim ins As String() = Console.ReadLine().Split(New Char(){" "c})
            Console.WriteLine(Int(ins(0))+Int(ins(1)))
        End Sub
    End Module
    

    Kotlin

    fun main(args: Array<String>) {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        println(a + b)
    }
    

    Haskell

    main = do
        [a, b] <- (map read . words) `fmap` getLine
        print (a+b)
    

    Lua

    a = io.read('*n')
    b = io.read('*n')
    print(a + b)
    

    OCaml

    Scanf.scanf "%i %i\n" (fun a b -> print_int (a + b))
    

    Julia

    nums = map(x -> parse(Int, x), split(readline(), " "))
    println(nums[1] + nums[2])
    

    Scala

    object Main extends App {
        println(scala.io.StdIn.readLine().split(" ").map(_.toInt).sum)
    }
    

    Perl

    my $in = <STDIN>;
    chomp $in;
    $in = [split /[\s,]+/, $in];
    my $c = $in->[0] + $in->[1];
    print "$c\n";
    
    • 1

    信息

    ID
    2
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    25
    已通过
    13
    上传者