链接:https://ac.nowcoder.com/acm/contest/5657/B
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
计算a+b
打开以下链接可以查看正确的代码
https://ac.nowcoder.com/acm/contest/5657#question

输入描述:
输入第一行包括一个数据组数t(1 <= t <= 100)
接下来每行包括两个正整数a,b(1 <= a, b <= 10^9)
输出描述:
输出a+b的结果
示例1
输入
复制
2
1 5
10 20
输出
复制
6
30

思路和心得

1.c++ cin>>

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int T;    cin >> T;
    while (T --)
    {
        int a;    cin >> a;
        int b;    cin >> b;
        cout << a + b << endl;
    }

    return 0;
}

稍微优化一下

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int T;    cin >> T;
    while (T --)
    {
        int a;    cin >> a;
        int b;    cin >> b;
        cout << a + b << endl;
    }

    return 0;
}

2.python3 int(input())

T = int(input())
for _ in range(T):
    a, b = map(int, input().split())
    print(a + b)

3.java nextInt()

import java.util.*;

public class Main
{
    public static void main(String [] args)
    {
        Scanner scan = new Scanner(System.in);

        int T = scan.nextInt();
        while (T -- > 0)
        {
            int a = scan.nextInt();
            int b = scan.nextInt();
            System.out.println(a + b);
        }

    }
}

稍微优化一下

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

public class Main
{
    public static void main(String [] args) throws Exception
    {
        BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));

        int T = Integer.parseInt(BR.readLine());
        while (T -- > 0)
        {
            String [] line1 = BR.readLine().split(" ");
            int a = Integer.parseInt(line1[0]);
            int b = Integer.parseInt(line1[1]);
            System.out.println(a + b);
        }

    }
}