This content is archived!

For the 2018-2019 school year, we have switched to using the WLMOJ judge for all MCPT related content. This is an archive of our old website and will not be updated.

These programs read in two integers on the same line, and output their sum.


Turing

var a, b : int
get a, b
put a + b

Java

import java.io.*;

public class ClassName{
	public static void main(String[] args) throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] tokens = in.readLine().split(" ");
		int a = Integer.parseInt(tokens[0]);
		int b = Integer.parseInt(tokens[1]);
		System.out.println(a + b);
	}
}

Java Alternate Method (May be too slow with large inputs)

java.util.Scanner;

public class ClassName{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		System.out.println(a + b);
	}
}

C/C++

#include <stdio.h>

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d", a + b);
}

C++ Alternate Method (May be too slow with large inputs)

#include <iostream>
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	cout << a + b;
}

Python 2

from sys import stdin       # Speeds up input
raw_input = stdin.readline  # (optional)

a, b = map(int, raw_input().split())
print a + b

Python 3

from sys import stdin       # Speeds up input
input = stdin.readline      # (optional)

a, b = map(int, input().split())
print(a + b)

Ruby

a, b = gets.split.map(&:to_i)
puts a + b

PHP

<?php
list($a, $b) = fscanf(STDIN, "%d %d");
echo $a + $b;
?>

Pascal

program input;

var a, b : integer;
begin
  read(a);
  read(b);
  writeln(a + b);
end.