1000. a + b problem

 

Find the value of a + b.

 

Input. Each line contains two integers a and b (|a|, |b| ≤ 30000).

 

Output. For each test case print the sum a + b in a separate line.

 

Sample input

Sample output

1 1

1 2

2

3

 

 

SOLUTION

elementary

 

Algorithm analysis

In this problem you must find the sum of two integers.

 

Algorithm realization

Compute the sum of two numbers until we reach the end of file.

 

while(scanf("%d %d",&a,&b) == 2)

  printf("%d\n",a + b);

 

Algorithm realizationpointers

 

#include <stdio.h>

 

int *a, *b;

 

int main(void)

{

  a = new (int);

  b = new (int);

  while(scanf("%d %d",a,b) == 2)

    printf("%d\n",*a + *b);

  delete a;

  delete b;

  return 0;

}

 

Java realization

 

import java.util.*;

 

public class Main

{

  public static void main(String[] args)

  {

    Scanner con = new Scanner(System.in);

    while(con.hasNext())

    {

      int a = con.nextInt();

      int b = con.nextInt();

      System.out.println(a + b);     

    }

    con.close();

  }

}

 

Python realization

 

import sys

for s in sys.stdin:

  a, b = map(int,s.split())

  print(a+b)