剑指offer A + B

剑指offer A + B

题目

输入两个整数,求这两个整数的和是多少。

输入格式

输入两个整数A,B,用空格隔开,0≤A,B≤10的8次幂

输出格式

输出一个整数,表示这两个数的和

样例输入:

3 4

样例输出:

7

参考答案

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()))

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; }));
  });
});

Go 代码

package main

import "fmt"

func main() {
  var a, b int
  for {
    n, _ := fmt.Scanf("%d %d", &a, &b)
    if n != 2 { break }
    fmt.Println(a + b)
  }
}

相关推荐

  1. offer A + B

    2023-12-18 21:50:01       60 阅读
  2. offer-第二版

    2023-12-18 21:50:01       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-18 21:50:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-18 21:50:01       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-18 21:50:01       82 阅读
  4. Python语言-面向对象

    2023-12-18 21:50:01       91 阅读

热门阅读

  1. 02_c++多线程_this_thread

    2023-12-18 21:50:01       54 阅读
  2. 部署虚拟web主机

    2023-12-18 21:50:01       56 阅读
  3. Go语言bufio包的使用

    2023-12-18 21:50:01       52 阅读
  4. 平面上点到直线的距离

    2023-12-18 21:50:01       70 阅读