Sample
posted on June 5, 2023, 12:12 p.m.
Python 2
N = int(raw_input())
for _ in xrange(N):
a, b = map(int, raw_input().split())
print a + b
Python 3
N = int(input())
for _ in range(N):
a, b = map(int, input().split())
print(a + b)
Java
import java.util.*;
public class APlusB {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
for (int i = 0; i < N; i++) {
int a = in.nextInt();
int b = in.nextInt();
System.out.println(a + b);
}
}
}
C++
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
cout << a + b << endl;
}
}
C
#include <stdio.h>
int main() {
int N;
scanf("%d\n", &N);
for (int i = 0; i < N; i++) {
int a, b;
scanf("%d %d\n", &a, &b);
printf("%d\n", a + b);
}
}
JS
print(...): similar to Python's print, prints all argument separated by space followed by new line.
flush(): flushes stdout, ensuring everything output by print() immediately shows up.
gets(): similar to the Ruby equivalent, returns one line of input from stdin.
read(bytes): read bytes bytes from stdin as an ArrayBuffer.
write(buffer): write a typed array, ArrayBuffer, or a view of ArrayBuffer to stdout.
quit(code): exits the program with code.
You can also assign to the global variable autoflush to control whether print() flushes.
Comments