A+B Problem 不同的语言
c
#include <stdio.h>
int main()
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d",a+b);
return 0;
}
cpp
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b;
return 0;
}
Python
s=raw_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
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;
Go
package main
import "fmt"
func main()
{
var a,b int
fmt.Scanf("%d%d",&a,&b)
fmt.Println(a+b)
}
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]))
}
}
Basic
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)
}
Perl
my $in=<STDIN>;
chomp $in
$in = [split /[\s,]+/, $in];
my $c=$in->[0]+$in->[1];
print "$c\n";
A+B不同的方法
普通
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<a+b;
}
LCT动态树
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstring>
using namespace std;
struct node
{
int data,rev,sum;
node *son[2],*pre;
bool judge();
bool isroot();
void pushdown();
void update();
void setson(node *child,int lr);
}lct[233];
int top,a,b;
node *getnew(int x)
{
node *now=lct+ ++top;
now->data=x;
now->pre=now->son[1]=now->son[0]=lct;
now->sum=0;
now->rev=0;
return now;
}
bool node