A + B Problem, this question, absorbing the essence of the world, is worthy of classic of the classic of classics. Since ancient times OIer will go through its experience (this is not to say it white?), Here I have to say something about solving the problem herobrine practices.
Well, comrades, we start with this question, towardJelly Bah, Gangster road marching.
Any great ideas, there is a small start.
High-energy front
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)
}
Mono C #
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";
Finally, that is, when the most energetic.
As we all know, my blogger is the main thing in C ++, so finally I brought the high-precision version of C ++:
#include<stdio.h>
#include<string.h>
int main()
{
char a[120],b[120];
int num1[120],num2[120];
int sum[120];
int len1,len2,len,i,temp;
scanf("%s%s",a,b);
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
memset(sum,0,sizeof(sum));
len1=strlen(a);
len2=strlen(b);
len=len1>len2?len1:len2;
for(i=0;i<len1;i++)
{
num1[i]=a[len1-i-1]-'0';
}
for(i=0;i<len2;i++)
{
num2[i]=b[len2-i-1]-'0';
}
for(i=0;i<len;i++)
{
sum[i]=num1[i]+num2[i];
}
for(i=0;i<len;i++)
{
temp=sum[i];
sum[i]=temp%10;
sum[i+1]+=temp/10;
}
if(sum[len]>0)
{
len++;
}
for(i=len-1;i>=0;i--)
{
printf("%d",sum[i]);
}
printf("\n");
return 0;
}
Here, then offer a small series of ultra-compact high-precision version of the A + B
Python
a=input()
b=input()
a=int(a)
b=int(b)
print(a+b)
END
Standard Outcome: