A+B Problem——经典中的经典
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——经典中的经典的更多相关文章
- MATLAB对于文本文件(txt)数据读取的技巧总结(经典中的经典)
振动论坛原版主eight的经典贴http://www.chinavib.com/thread-45622-1-1.html MATLAB对于文本文件(txt)进行数据读取的技巧总结(经典中的经典)由于 ...
- Java堆、栈和常量池以及相关String的详细讲解(经典中的经典) (转)
原文链接 : http://www.cnblogs.com/xiohao/p/4296088.html 一:在JAVA中,有六个不同的地方可以存储数据: 1. 寄存器(register). 这是最快的 ...
- 个人收藏的flex特效网址【经典中的极品】
http://www.noupe.com/adobe/flex-developers-toolbox-free-components-themes-and-tutorials.html经典中的经典 h ...
- Java中的经典算法之冒泡排序(Bubble Sort)
Java中的经典算法之冒泡排序(Bubble Sort) 神话丿小王子的博客主页 原理:比较两个相邻的元素,将值大的元素交换至右端. 思路:依次比较相邻的两个数,将小数放在前面,大数放在后面.即在第一 ...
- Java中的经典算法之选择排序(SelectionSort)
Java中的经典算法之选择排序(SelectionSort) 神话丿小王子的博客主页 a) 原理:每一趟从待排序的记录中选出最小的元素,顺序放在已排好序的序列最后,直到全部记录排序完毕.也就是:每一趟 ...
- C语言中的经典例题用javascript怎么解?(一)
C语言中的经典例题用javascript怎么解?(一) 一.1+2+3+……+100=? <script type="text/javascript"> ...
- 如何在ubuntu 12.04 中安装经典的 GNOME桌面
这次介绍的是如何在ubuntu 12.04 中安装经典的 GNOME桌面,默认的 Ubuntu 12.04 默认unity桌面,一些用户不喜欢 Unity 桌面,所以想找回昔日的经典Gnome桌面. ...
- Linux 运维工作中的经典应用ansible(批量管理)Docker容器技术(环境的快速搭建)
一 Ansible自动化运维工具 Python 在运维工作中的经典应用 ansible(批量管理操作) .安装ansible(需要bese epel 2种源) wget -O /etc/yum.rep ...
- 如何在 Azure 中的经典 Windows 虚拟机上设置终结点
在 Azure 中使用经典部署模型创建的所有 Windows 虚拟机都可以通过专用网络通道与同一云服务或虚拟网络中的其他虚拟机自动通信. 但是,Internet 或其他虚拟网络中的计算机需要终结点将入 ...
随机推荐
- UVA 10200 Prime Time【暴力,精度】
题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_proble ...
- maven 新建项目时修改默认jre路径
新建maven项目时,JRE System Library默认为J2SE-1.5 如果想修改为1.7,修改maven的settings.xml ,在profiles中添加 <profile> ...
- 使用Python将数据插入数据库(一)
假如我现在有一个Excel数据表格,需要将其数据插入MySQL数据库中.数据如下: 对应的Python实现代码如下: #导入需要使用到的数据模块 import pandas as pd import ...
- Cg入门6:函数2
内建函数分为四类: 1.数学函数 2.几何函数 3.纹理函数 4.导数函数:事实上就是片段函数
- 我所写的CNN框架 VS caffe
我所写的CNN框架 VS caffe 一个月前.自己模仿caffe实现了一个卷积神经网络的框架. 同样点 1无缝支持CPU和GPU模式,GPU模式使用cuda实现. 不同点 1我的CNN不依赖与不论什 ...
- SGU - 311 Ice-cream Tycoon(线段树)
Description You've recently started an ice-cream business in a local school. During a day you have m ...
- vi下对齐代码的操作
时不时会用到,但easy忘,在这里记录一下 1. ctrl + v (选中块) 2. ctrl + f (向前) 或 ctrl +v (向后) 3. 按"=", 把选中的代码对齐
- 嵌入式开发之davinci--- mcfw框架介绍
整体上mcfw框架如下图 从中可见其层次是清楚的,link实在基本的驱动之上的,而mcfw是在link之上的api,是通过link来实现相应的功能.可见link是框架中承上启下的层次,通过link来实 ...
- Xcode中使用git
项目中添加git 也可在开始新建项目时勾选git,这是针对开始没有勾选git的情况 打开终端 cd 项目文件目录 //初始化一个代码仓库, git init //将当前目录及子目录中的文件标记为要添加 ...
- TCP Operational Overview and the TCP Finite State Machine (FSM) http://tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF.htm
http://tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF.htm http://tcpipgu ...