Languages
CSES currently supports the following languages:
| language | version | compiler flags | packages |
|---|---|---|---|
| Assembly | NASM 2.15.05 | | |
| C | gcc 11.4.0 | -std=c99 -O2 -Wall | |
| C++ | g++ 11.4.0 | -std=c++11 -O2 -Wall-std=c++17 -O2 -Wall-std=c++20 -O2 -Wall | |
| Haskell | GHC 9.2.8 | -O2 -Wall | show list |
| Java | Java 11.0.25 | | |
| Make | Make 4.3 | | |
| Node.js | Node.js 12.22.9 | | |
| Pascal | FPC 3.2.2 | -O2 | |
| Python2 | CPython 2.7.18 PyPy 2.7.18 | | |
| Python3 | CPython 3.10.12 PyPy 3.8.13 | | |
| Ruby | ruby 3.0.2 | | |
| Rust | rustc 1.75.0 | --edition=2018 -C opt-level=3--edition=2021 -C opt-level=3 | rand 0.8.4 |
| Scala | Scala 2.11.12 | |
Note that all languages are not be available in all courses and contests.
The source code size limit is 128 kB for all languages.
Example programs
Here are examples on how to solve the A + B problem in the supported languages.
Assembly
section .text
global _start
atoi: xor rax,rax
xor rdx,rdx
lodsb
cmp al,'-'
sete bl
jne .lpv
.lp: lodsb
.lpv: sub al,'0'
jl .end
imul rdx,10
add rdx,rax
jmp .lp
.end: test bl,bl
jz .p
neg rdx
.p ret
itoa: std
mov r9,10
bt rax,63
setc bl
jnc .lp
neg rax
.lp: xor rdx,rdx
div r9
xchg rax,rdx
add rax,'0'
stosb
xchg rax,rdx
test rax,rax
jnz .lp
test bl,bl
jz .p
mov al,'-'
stosb
.p: cld
inc rdi
ret
_start: xor rax,rax
xor rdi,rdi
mov rsi,buff
mov rdx,100
syscall
mov rsi,buff
lodsb
mov rsi,buff
call atoi
mov rcx,rdx
call atoi
add rcx,rdx
mov rdi,buff+99
mov rsi,rdi
std
mov rax,10
stosb
mov rax,rcx
call itoa
sub rsi,rdi
mov rdx,rsi
mov rsi,rdi
inc rdx
mov rax,1
mov rdi,rax
syscall
mov rax,60
xor rdi,rdi
syscall
section .bss
buff: resb 100
C
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d\n", a+b);
}
C++
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a+b << "\n";
}
Haskell
main :: IO()
main = do
line <- getLine
let [a, b] = map read (words line)
print (a + b)
Java
import java.util.*;
public class Sum {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
System.out.println(a+b);
}
}
Node.js
var readline = require('readline');
var r = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
r.on('line', function (line) {
var vals = line.split(" ");
console.log(parseInt(vals[0])+parseInt(vals[1]));
});
Pascal
var
a, b: longint;
begin
readln(a,b);
writeln(a+b);
end.
Python2
a,b = [int(x) for x in raw_input().split()] print(a+b)
Python3
a,b = [int(x) for x in input().split()] print(a+b)
Ruby
a,b = gets.split.map &:to_i puts a+b
Rust
use std::io::{BufRead, BufReader};
fn main() {
let mut input = BufReader::new(std::io::stdin());
let mut line = "".to_string();
input.read_line(&mut line).unwrap();
let mut split = line.split_whitespace();
let a: i32 = split.next().unwrap().parse().unwrap();
let b: i32 = split.next().unwrap().parse().unwrap();
println!("{}", a + b);
}
Scala
object Sum {
def main(args: Array[String]): Unit = {
val Array(a,b) = readLine.split(" ").map(_.toInt)
println(a+b)
}
}
