1000:A+B

时间限制: 1 S | 内存限制: 65536 KB
Accept: 447 | Submit: 1038
[提交] [状态] [讨论版]
描述

calculate a+b

输入

Two integer a,b (0<=a,b<=10)

输出

Output a+b

样例输入

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


Python3:

Python2的raw_input就是Python3的input



多组输入:


while True:

    try:

        a,b = (int(x) for x in raw_input().split())

        ...

    except:

        break

来源
POJ