题目描述
输入两个整数,求这两个整数的和是多少。
输入格式
输入两个整数A,B,用空格隔开,$0≤A,B≤10^8$
输出格式
输出一个整数,表示这两个数的和
样例
样例输入:
3 4
样例输出:
7
模拟
$O(1)$
简单的A+B运算啦.
C
#include <stdio.h>
int main() {
int a,b;
scanf("%d%d",&a,&b);
printf("%d", a+b);
return 0;
}
C++
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int a,b;
cin >> a >> b;
cout << a+b;
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)
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";
抄洛谷也不注明出处:Link
C++中的con,cin是什么操作,有点没看懂
只有
cin
吧,con
在哪里呢?cin
是读入操作,比如我声明了变量a
,cin>>a
就是从标准输入里读入a
js好难