A+B Problem,这道题,吸收了天地的精华,是当之无愧的经典中的经典中的经典。自古以来OIer都会经过它的历练(这不是白说吗?),下面就有我herobrine来讲讲这道题的各种做法。

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

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

前方高能

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

最后,也就是最高能的时候。

大家都知道,我博主是主攻C++的嘛,所以,最后我带来了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;
}

这里,小编再奉上一份超简洁的A+B高精版

Python

a=input()
b=input()
a=int(a)
b=int(b)
print(a+b)

END

标准结局:

A+B Problem——经典中的经典的更多相关文章

  1. MATLAB对于文本文件(txt)数据读取的技巧总结(经典中的经典)

    振动论坛原版主eight的经典贴http://www.chinavib.com/thread-45622-1-1.html MATLAB对于文本文件(txt)进行数据读取的技巧总结(经典中的经典)由于 ...

  2. Java堆、栈和常量池以及相关String的详细讲解(经典中的经典) (转)

    原文链接 : http://www.cnblogs.com/xiohao/p/4296088.html 一:在JAVA中,有六个不同的地方可以存储数据: 1. 寄存器(register). 这是最快的 ...

  3. 个人收藏的flex特效网址【经典中的极品】

    http://www.noupe.com/adobe/flex-developers-toolbox-free-components-themes-and-tutorials.html经典中的经典 h ...

  4. Java中的经典算法之冒泡排序(Bubble Sort)

    Java中的经典算法之冒泡排序(Bubble Sort) 神话丿小王子的博客主页 原理:比较两个相邻的元素,将值大的元素交换至右端. 思路:依次比较相邻的两个数,将小数放在前面,大数放在后面.即在第一 ...

  5. Java中的经典算法之选择排序(SelectionSort)

    Java中的经典算法之选择排序(SelectionSort) 神话丿小王子的博客主页 a) 原理:每一趟从待排序的记录中选出最小的元素,顺序放在已排好序的序列最后,直到全部记录排序完毕.也就是:每一趟 ...

  6. C语言中的经典例题用javascript怎么解?(一)

    C语言中的经典例题用javascript怎么解?(一) 一.1+2+3+……+100=?        <script type="text/javascript">  ...

  7. 如何在ubuntu 12.04 中安装经典的 GNOME桌面

    这次介绍的是如何在ubuntu 12.04 中安装经典的 GNOME桌面,默认的 Ubuntu 12.04 默认unity桌面,一些用户不喜欢 Unity 桌面,所以想找回昔日的经典Gnome桌面. ...

  8. Linux 运维工作中的经典应用ansible(批量管理)Docker容器技术(环境的快速搭建)

    一 Ansible自动化运维工具 Python 在运维工作中的经典应用 ansible(批量管理操作) .安装ansible(需要bese epel 2种源) wget -O /etc/yum.rep ...

  9. 如何在 Azure 中的经典 Windows 虚拟机上设置终结点

    在 Azure 中使用经典部署模型创建的所有 Windows 虚拟机都可以通过专用网络通道与同一云服务或虚拟网络中的其他虚拟机自动通信. 但是,Internet 或其他虚拟网络中的计算机需要终结点将入 ...

随机推荐

  1. hdu - 5007 Post Robot (水题)

    http://acm.hdu.edu.cn/showproblem.php?pid=5007 #include<iostream> #include<stdio.h> #inc ...

  2. LightOJ1094 - Farthest Nodes in a Tree(树的直径)

    http://lightoj.com/volume_showproblem.php?problem=1094 Given a tree (a connected graph with no cycle ...

  3. 转 从头到尾彻底解析Hash表算法

    出处:http://blog.csdn.net/v_JULY_v.   说明:本文分为三部分内容,     第一部分为一道百度面试题Top K算法的详解:第二部分为关于Hash表算法的详细阐述:第三部 ...

  4. Zookeeper开发常见问题

    背景与目的 Zookeeper开发过程中遇到一些常见问题,为了后续开发不犯同样的错误,总结一下此类问题,并进行分析和解决. 适合人员 主要适合zookeeper开发.测试及运维相关人员. 问题与解决 ...

  5. Python中字符运算的优先级

    表1-2 运算符优先级 运算符 描述 lambda Lambda表达式 or 布尔“或” and 布尔“与” not x 布尔“非” in,not in 成员测试 is,is not 同一性测试 &l ...

  6. python学习第一

    #python学习day1#一.变量#变量命名规范:#驼峰命名法:AgeOfPlane#下划线命名(推荐):age_of_plane#变量格式同C/C++#注意:变量不以中文命名:变量不宜过长:变量因 ...

  7. [iOS]经常使用正則表達式

    经常使用正則表達式大全!(比如:匹配中文.匹配html) 匹配中文字符的正則表達式: [u4e00-u9fa5]    评注:匹配中文还真是个头疼的事,有了这个表达式就好办了 匹配双字节字符(包含汉字 ...

  8. 错误 1 无法将程序集“NBear.Data.dll”复制到文件“D:\newbpm\bpm\SureBpm\Bin\NBear.Data.dll”。无法将“D:\newbpm\bpm\SureSoft.WebServiceBaseLib\bin\Debug\NBear.Data.dll”添加到网站。 无法添加文件“Bin\NBear.Data.dll”。 拒绝访问。 D:\..

    错误 1 无法将程序集“NBear.Data.dll”复制到文件“D:\newbpm\bpm\SureBpm\Bin\NBear.Data.dll”.无法将“D:\newbpm\bpm\SureSof ...

  9. 【bzoj1561】[JSOI2009]去括号

    #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> # ...

  10. HashMap与HashTable的区别?

    HashMap和Hashtable的比较是Java面试中的常见问题,用来考验程序员是否能够正确使用集合类以及是否可以随机应变使用多种思路解决问题.HashMap的工作原理.ArrayList与Vect ...