跳到正文

闲话

P1001 A+B Problem的一百种解法 (TODO)

happylittlepig约 10 分钟
原文
文章信息与版本

文章信息

发布
2024年6月15日
收录
2025年12月12日
更新
2026年11月3日
篇幅
约 10 分钟

版本

  1. v1当前

A+B Problem

题目背景

强烈推荐新用户必读帖。

不熟悉算法竞赛的选手请看这里:

算法竞赛中要求的输出格式中,不能有多余的内容,这也包括了“请输入整数 a\bm a 和 b\bm b” 这一类的提示用户输入信息的内容。若包含了这些内容,将会被认为是 Wrong Answer,即洛谷上的 WA。在对比代码输出和标准输出时,系统将忽略每一行结尾的空格,以及最后一行之后多余的换行符。

若因此类问题出现本机似乎输出了正确的结果,但是实际提交结果为错误的现象,请勿认为是洛谷评测机出了问题,而是你的代码中可能存在多余的输出信息。用户可以参考在题目末尾提供的代码。

此外,请善用应用中的在线 IDE 功能,以避免不同平台的评测产生差异。

最后,请不要在对应的题目讨论区中发布自己的题解,请发布到题解区域中,否则将处以删除或禁言的处罚。若发现无法提交题解则表明本题题解数量过多,仍不应发布讨论。若您的做法确实与其他所有题解均不一样,请联系管理员添加题解。

题目描述

输入两个整数 a,ba, b,输出它们的和(∣a∣,∣b∣≤109|a|,|b| \le {10}^9)。

注意

  1. Pascal 使用 integer 会爆掉哦!
  2. 有负数哦!
  3. C/C++ 的 main 函数必须是 int 类型,而且 C 最后要 return 0。这不仅对洛谷其他题目有效,而且也是 NOIP/CSP/NOI 比赛的要求!

好吧,同志们,我们就从这一题开始,向着大牛的路进发。

任何一个伟大的思想,都有一个微不足道的开始。

输入格式

两个以空格分开的整数。

输出格式

一个整数。

样例 #1

样例输入 #1

代码
20 30

样例输出 #1

代码
50

Pascal(1种)

1

C++
var a, b: longint;
begin
    readln(a,b);
    writeln(a+b);
end.
C++
//没学过qwq

Python2(1种)

2

C++
s = raw_input().split()
print int(s[0]) + int(s[1])
C++
//没学过qwq

Python3(1种)

3

C++
s = input().split()
print(int(s[0]) + int(s[1]))
C++
//没学过qwq

Java(1种)

4

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);
    }
}
C++
//没学过qwq

JavaScript (Node.js)(1种)

5

JavaScript
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() // 请注意必须在出口点处加入此行
C++
//没学过qwq

Ruby(1种)

6

ruby
a, b = gets.split.map(&:to_i)
print a+b
C++
//没学过qwq

PHP(1种)

7

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

Rust(1种)

8

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);
}
C++
//没学过qwq

Go(1种)

9

Go
package main

import "fmt"

func main() {
    var a, b int
    fmt.Scanf("%d%d", &a, &b)
    fmt.Println(a+b)
}
C++
//没学过qwq

C# Mono(1种)

10

cs
using System;

public class APlusB{
    private static void Main(){
        string[] input = Console.ReadLine().Split(' ');
        Console.WriteLine(int.Parse(input[0]) + int.Parse(input[1]));
    }
}
C++
//没学过qwq

Visual Basic Mono(1种)

11

vb
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
C++
//没学过qwq

Kotlin(1种)

12

kotlin
fun main(args: Array<String>) {
    val (a, b) = readLine()!!.split(' ').map(String::toInt)
    println(a + b)
}
C++
//没学过qwq

Haskell(1种)

13

haskell
main = do
    [a, b] <- (map read . words) `fmap` getLine
    print (a+b)
C++
//没学过qwq

Lua(1种)

14

lua
a = io.read('*n')
b = io.read('*n')
print(a + b)
C++
//没学过qwq

OCaml(1种)

15

ocaml
Scanf.scanf "%i %i\n" (fun a b -> print_int (a + b))
C++
//没学过qwq

Julia(1种)

16

julia
nums = map(x -> parse(Int, x), split(readline(), " "))
println(nums[1] + nums[2])
C++
//没学过qwq

Scala(1种)

17

scala
object Main extends App {
    println(scala.io.StdIn.readLine().split(" ").map(_.toInt).sum)
}
C++
//没学过qwq

Perl(1种)

18

perl
my $in = <STDIN>;
chomp $in;
$in = [split /[\s,]+/, $in];
my $c = $in->[0] + $in->[1];
print "$c\n";
C++
//没学过qwq

C(2种)

19

C
#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d\n", a+b);
    return 0;
}

20

C
#include <stdio.h>

int main()
{
    long long a,b;
    scanf("%lld %lld",&a,&b);
    printf("%d\n", a+b);
    return 0;
}
C++
//学过一点点qwq

C++(80种)

21

C++
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
}

22

C++
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    long long a,b;
    cin >> a >> b;
    cout << a + b << endl;
    return 0;
}

23

C++
#include <iostream>
#define 加 +
#define 整型 int
#define 输入 cin
#define 输出 cout
#define 变量一 num1
#define 变量二 num2
using namespace std;
int main(int argc, char** argv) {
	整型 变量一 = 0, 变量二 = 0;
	输入 >> 变量一 >> 变量二;
	输出 << 变量一 加 变量二;
	return 0;
}
C++
//学过亿点点qwq
原文