Compilation
Pour un fichier A.cpp
make A
La commande officielle est :
g++ -x c++ -Wall -Wextra -O2 -std=gnu++20 -static -pipe A.cpp -o A
C++ compilation flags
If we take a obviously bad code:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void) {
int t[5];
cout << t[6] << endl;
return 0;
}
If your compiler flags contain (i.e. the “args” of your tasks.json config file in VSCode/Codium):
"-fsanitize=address",
"-fsanitize=undefined",
"-std=c++20",
Then you should have some nice error message:
bad.cpp:7:16: runtime error: index 6 out of bounds for type 'int [5]'
bad.cpp:7:16: runtime error: load of address 0x7fffffffd5d8 with insufficient space for an object of type 'int'
Tests
Pour exécuter un fichier de tests :
./A < A.in
Pour exécuter un tas de fichiers de tests :
for x in *in; do ./A < $x; done
cat *out # Pour comparer
You may want to check cph competitive programming helper. There are browser extensions to import the testcases in VSCode or other IDEs.
Graphviz
Pour visualiser un graphe, la syntaxe est la suivante :
digraph G {
rankdir=LR;
s -> 1 [label=1];
s -> 2;
1 -> 3;
1 -> 4 [label=1];
2 -> 4;
3 -> t;
4 -> t [label=1];
}
Et la commande :
dot -Tpng graph.dot > graph.png
Donne le graphe suivant :
Par exemple, ce code C++ peut faire l’affaire :
En remplaçant éventuellement flow
par capacity
.
Version OCaml
Merci à Clémence Réda pour cette version.