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. Google的Guava类库简介(转)

    说明:信息虽然有点旧,至少可以先了解个大概. Guava是一个Google的基于Java的类库集合的扩展项目,包括collections, caching, primitives support, c ...

  2. Activiti-5.3工作流引擎-源码解析(流程文档解析)

    前面我们通过BPMN20.xsd和Activiti自定义的XML Schema文件初步了解了业务流程模型的定义,那么现在我们来了解一下流程文档的解析过程,这个过程主要是通过代码解析来完成. 代码解析过 ...

  3. hash_map与unordered_map区别

    http://blog.csdn.net/blues1021/article/details/45054159

  4. 【APUE】进程间通信之管道

    管道是UNIX系统IPC最古老形式,并且所有UNIX系统都提供此种通信机制.管道由下面两种局限性: 1)历史上,它们是半双工的(即数据只能在一个方向上流动) 2)它们只能在具有公共祖先的进程之间使用. ...

  5. Jackson说明

    Jackson说明 package com.stono.sboot2_chp4_jackson.controller; import com.fasterxml.jackson.annotation. ...

  6. uva live 12846 A Daisy Puzzle Game

    假设下一个状态有必败.那么此时状态一定是必胜,否则此时状态一定是必败 状压DP #include<iostream> #include<map> #include<str ...

  7. hdoj 3351 Seinfeld 【栈的简单应用】

    Seinfeld Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  8. [Angular] Communicate Between Components Using Angular Dependency Injection

    Allow more than one child component of the same type. Allow child components to be placed within the ...

  9. es5~es6

    1.用箭头函数减少代码(相信你在Vue已经看到了) ES5: function greetings (name) { return 'hello ' + name } ES6: const greet ...

  10. VS code - code Snippet

    For anyone working on the UI and using VS Code, you can create a user Snippet and keyboard shortcut ...