| 描述 |
|---|
calculate a+b. |
| 输入 |
Two integer a, b. (0<=a, b<=10) |
| 输出 |
Output a+b and line feed. |
| 样例输入 |
1 2 |
| 样例输出 |
3 |
| HINT |
C++
#include "iostream"
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a + b << endl;
return 0;
}
多组案例
while(cin >> a >> b)
{
...
}
C
#include "stdio.h"
int main()
{
int a,b;
scanf("%d %d",&a, &b);
printf("%d\n",a + b);
return 0;
}
多组案例
while(scanf("%d%d", &a,&b) != EOF) // 或 while(~scanf("%d%d", &a,&b))
{
...
}
JAVA(因语言特性 主类名统一取名 Main)禁用无关的类和方法
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
System.out.println(a + b);
}
}
多组案例
while(scanner.hasNextInt())
{
int a = scanner.nextInt();
int b = scanner.nextInt();
...
}
Python2
a, b = (int(x) for x in raw_input().split()) print(a + b)或者
print sum(map(int,raw_input().split()))多组案例
while True: try: a, b = (int(x) for x in raw_input().split()) ... except: breakPython2的raw_input就是Python3的input |
| 来源 |
| POJ |