Your first algo program
This tutorial assumes you already cloned the repo and can run the commands from the quickstart.
The A+B problem
Section titled “The A+B problem”Start with the smallest useful program: read two integers and print their sum.
input: a, b: intprintln a + bCompile and run it:
./algo compile aplusb.alg -o aplusb.cppg++ -std=c++17 -O2 aplusb.cpp -o aplusbecho "3 4" | ./aplusbOutput:
7This shows the core workflow:
- write an
.algfile - compile it to
.cpp - compile the C++
- run the binary
What algo generated
Section titled “What algo generated”The generated C++ is ordinary contest-style code:
#include <bits/stdc++.h>using namespace std;typedef long long ll;int main() { cin.tie(nullptr)->sync_with_stdio(false); int a, b; cin >> a >> b; cout << (a + b); cout << "\n"; return 0;}There is no VM or hidden runtime. You can inspect the output and reason about what it will do when you submit it.
What the source means
Section titled “What the source means”input:reads values in declaration ordera, b: intdeclares two integersprintlnprints one line
That is enough for a large class of introductory contest problems.
One more example
Section titled “One more example”Codeforces 4A (Watermelon): given weight w, can it be split into two even positive parts?
input: w: intif w > 2 and w % 2 == 0: println "YES"else: println "NO"./algo compile watermelon.alg -o watermelon.cppg++ -std=c++17 -O2 watermelon.cpp -o watermelonecho "8" | ./watermelonecho "5" | ./watermelonOutputs:
YESNOThis adds two new pieces of syntax:
if / elseuses indentation instead of braces- string literals print directly with
println