Can someone explain this code?

Strange. I completely agree with you that this is not syntactically-correct C or C++. What's strange is that it supposedly passes the tests on codefights, here.

There README says that they are using g++ 5.0, but I can't see how it can compile, and in fact it doesn't compile with g++ 5.2.0 and --std=c++14.

C++

We support g++ 5.0 with C++14 features enabled. Feel free to use unordered_map, regex, range for, auto ... features from C++11 and 14 standards. The following libraries are automatically included:

include <iostream>

include <vector>

include <cstdarg>

include <string>

include <cstdio>

include <cctype>

include <cmath>

include <queue>

include <map>

include <set>

include <algorithm>

include <climits>

include <sstream>

include <numeric>

include <iterator>

include <iomanip>

include <utility>

include <stack>

include <functional>

include <deque>

include <complex>

include <bitset>

include <list>

include <array>

include <regex>

include <unordered_set>

include <unordered_map>

Some best practices for C++.

When declaring global variables in C++, initializing them during declaration will result in a syntax error. Instead, perform an initialization in the function/method. Static variables are disabled in C++, so using them will lead to unexpected results. Add using namespace std; at the beginning of the function in order to use std features without std:: prefix. Please use std::cout to print any data for debugging purposes. Use C++11 and 14 features, e.g. for (x: vec) {...}, lambda functions [](int a, int b) -> bool {...}.

/r/learnprogramming Thread Parent