题解 | #OJ在线编程常见输入输出练习场--A+B(1)# c++/python3/java
A+B(1)
https://ac.nowcoder.com/acm/contest/5657/A
链接:https://ac.nowcoder.com/acm/contest/5657/A
来源:牛客网
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
计算a+b
打开以下链接可以查看正确的代码
https://ac.nowcoder.com/acm/contest/5657#question
输入描述:
输入包括两个正整数a,b(1 <= a, b <= 10^9),输入数据包括多组。
输出描述:
输出a+b的结果
示例1
输入
复制
1 5
10 20
输出
复制
6
30
思路和心得
1. c++ cin>>即可
//c++代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a;
int b;
while (cin >> a)
{
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 a;
int b;
while (cin >> a)
{
cin >> b;
cout << a + b << endl;
}
return 0;
}2.python3 map(int, split())
#python3代码
while True:
try:
a, b = map(int, input().split())
print(a + b)
except:
break3.java nextInt()
//java代码
import java.util.*;
public class Main
{
public static void main(String [] args)
{
Scanner scan = new Scanner(System.in);
while (scan.hasNext())
{
int a = scan.nextInt();
int b = scan.nextInt();
System.out.println(a + b);
}
}
}
查看9道真题和解析