AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

洛谷 1001. A+B Problem    原题链接    简单

作者: 作者的头像   lkjy ,  2025-05-10 11:00:02 · 山东 ,  所有人可见 ,  阅读 3


0


在洛谷,若被发现存在抄袭题解的行为,可能会被处罚。


算法

代码

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.

Python 3

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]));
    }
}

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";

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息