第二题参考代码

root 站长 2021-01-21 16:36:45 2023-11-07 17:49:25 29

C++ 代码

#include <iostream>

using namespace std;

int main () { int a, b; cin >> a >> b; cout << a + b << endl; return 0; }

C 代码

#include <stdio.h>

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", a + b);
    return 0;
}

Java 代码

import java.io.*;
import java.util.*;

public class Main { public static void main(String args[]) throws Exception { Scanner cin=new Scanner(System.in); var a = cin.nextInt(); var b = cin.nextInt(); System.out.println(a + b); } }

Python 代码

import sys

for line in sys.stdin: print sum(map(int, line.split()))

Python3 代码

import sys

for line in sys.stdin: print(sum(map(int, line.split())))

Javascript 代码

var fs = require('fs');
var buf = '';

process.stdin.on('readable', function() { var chunk = process.stdin.read(); if (chunk) buf += chunk.toString(); });

process.stdin.on('end', function() { buf.split('\n').forEach(function(line) { var tokens = line.split(' ').map(function(x) { return parseInt(x); }); if (tokens.length != 2) return; console.log(tokens.reduce(function(a, b) { return a + b; })); }); });

作者:yxc
链接:https://www.acwing.com/solution/content/729/
来源:AcWing
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

{{ vote && vote.total.up }}

共 8 条回复

jsq 蒟蒻

请使用C++11(Clang)

#include <iostream>
using namespace std;

int main() {
    int,;
    cin >>>>;
    cout <<+;

    return 0;
}

最关键还AC了

jsq 蒟蒻
#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::judge() {
	return pre->son[1] == this;
}
bool node::isroot() {
	if (pre == lct)return true;
	return !(pre->son[1] == this || pre->son[0] == this);
}
void node::pushdown() {
	if (this == lct || !rev)return;
	swap(son[0], son[1]);
	son[0]->rev ^= 1;
	son[1]->rev ^= 1;
	rev = 0;
}
void node::update() {
	sum = son[1]->sum + son[0]->sum + data;
}
void node::setson(node *child, int lr) {
	this->pushdown();
	child->pre = this;
	son[lr] = child;
	this->update();
}
void rotate(node *now) {
	node *father = now->pre, *grandfa = father->pre;
	if (!father->isroot()) grandfa->pushdown();
	father->pushdown();
	now->pushdown();
	int lr = now->judge();
	father->setson(now->son[lr ^ 1], lr);
	if (father->isroot()) now->pre = grandfa;
	else grandfa->setson(now, father->judge());
	now->setson(father, lr ^ 1);
	father->update();
	now->update();
	if (grandfa != lct) grandfa->update();
}
void splay(node *now) {
	if (now->isroot())return;
	for (; !now->isroot(); rotate(now))
		if (!now->pre->isroot())
			now->judge() == now->pre->judge() ? rotate(now->pre) : rotate(now);
}
node *access(node *now) {
	node *last = lct;
	for (; now != lct; last = now, now = now->pre) {
		splay(now);
		now->setson(last, 1);
	}
	return last;
}
void changeroot(node *now) {
	access(now)->rev ^= 1;
	splay(now);
}
void connect(node *x, node *y) {
	changeroot(x);
	x->pre = y;
	access(x);
}
void cut(node *x, node *y) {
	changeroot(x);
	access(y);
	splay(x);
	x->pushdown();
	x->son[1] = y->pre = lct;
	x->update();
}
int query(node *x, node *y) {
	changeroot(x);
	node *now = access(y);
	return now->sum;
}
int main() {
	scanf("%d%d", &a, &b);
	node *A = getnew(a);
	node *B = getnew(b);
	connect(A, B);
	cut(A, B);
	connect(A, B);
	printf("%d\n", query(A, B));
	return 0;
}

搬运至CPP巨佬

wangyuzhe 蒟蒻
<?php
fscanf(STDIN, "%d", $a, $b);
echo ($a+$b);
?>
CPP 刷题王
CPP 刷题王
CPP 刷题王

C

#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n", a+b);
    return 0;
}

C++

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    cout << a+b << endl;
    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 ```cpp $input = trim(file_get_contents("php://stdin")); list($a, $b) = explode(' ', $input); echo $a + $b; ``` Rust ```cpp 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 ```cpp package main import "fmt" func main() { var a, b int fmt.Scanf("%d%d", &a, &b) fmt.Println(a+b) } ``` C# Mono ```cpp 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 ```cpp 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 ```cpp fun main(args: Array) { val (a, b) = readLine()!!.split(' ').map(String::toInt) println(a + b) } ``` Haskell ```cpp main = do [a, b] <- (map read . words) `fmap` getLine print (a+b) ``` Scala ```cpp object Main extends App { println(scala.io.StdIn.readLine().split(" ").map(_.toInt).sum) } ``` Perl ```cpp my $in = ; chomp $in; $in = [split /[\s,]+/, $in]; my $c = $in->[0] + $in->[1]; print "$c\n"; ```
Kinghero King of the summit

C++ 代码

#include

using namespace std;

int main () { int a, b; cin >> a >> b; cout << a + b << endl; return 0; } C 代码

#include <stdio.h>

int main() { int a, b; scanf("%d%d", &a, &b); printf("%d\n", a + b); return 0; } Java 代码

import java.io.; import java.util.;

public class Main { public static void main(String args[]) throws Exception { Scanner cin=new Scanner(System.in); var a = cin.nextInt(); var b = cin.nextInt(); System.out.println(a + b); } } Python 代码

import sys

for line in sys.stdin: print sum(map(int, line.split())) Python3 代码

import sys

for line in sys.stdin: print(sum(map(int, line.split()))) Javascript 代码

var fs = require('fs'); var buf = '';

process.stdin.on('readable', function() { var chunk = process.stdin.read(); if (chunk) buf += chunk.toString(); });

process.stdin.on('end', function() { buf.split('\n').forEach(function(line) { var tokens = line.split(' ').map(function(x) { return parseInt(x); }); if (tokens.length != 2) return; console.log(tokens.reduce(function(a, b) { return a + b; })); }); }); 作者:yxc 链接:https://www.acwing.com/solution/content/729/ 来源:AcWing 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

共 1 条回复

null him

感觉还是c++** or **c语言最容易看懂,其他要么是没有加号要么就是一大堆看不懂