All this information is readily found in any online docs about C++. Please read those.
All this information is readily found in any online docs about C++. Please read those.
https://isocpp.org/blog/2015/09/stroustrup-cppcon15-keynote
(For context, I'm mainly a C / Python / Unix Programmer, with an interest in common sense and architectures based on clean plain data interfaces instead of wrong abstractions, and with a good track on SPOJ)
- using namespace std;
- variable names inconsistent and random, using uppercase and lowercase randomly (code also would not compile since it is cased randomly)
- indenting and braces inconsistent
- use of macros for trivial tasks where they are absolutely not required
- use of macros in totally dangerous ways ("#define all(c) c.begin(), c.end()", seriously?)
- usage of compiler dependent features
- code should be for "competitive programming", and proposes a vector of vectors to make a 2D matrix
- Counterproductive and unhelpful typedefs
EDIT:
I'd like to tell you more, but looking at that page is making me feel unwell. The ostringstream example seems to be out of a nightmare. Just learn C++ from a reputable source and save yourself and everybody else around you the pain.
Before people lynch me, I just wants emphasize again that I'm not defending these practices in production code, but the article wasn't advocating that either. And of course there's the old debate about whether the contests themselves become harmful because they encourage bad practice, and that may be true, but that's a different conversation.
Perhaps we should read "competitive programming" as "programming quickly without regard for quality." Taken that way, the article could even be titled "programming to impress nontechnical managers so you can become one."
what would be the right way to do this?
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#defile all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())Just write C. C++ is too much of a pain.
If you want to get good at C++, there are no shortcuts. Read books (Scott Meyers, Bjarne Stroustrup), read Herb Sutter's GotW series, but don't read this.
You have to keep in mind that code for this kind of competitions is generally write only and uses basic facilities of a language to solve given algorithmic problem as fast as possible. Consistency isn't important when your solution fits on a single page.
lots of macros to do operations quickly, the code is not even readable.
vector< vector<int> >
Who even does that?Of course, it should also be std::vector<std::vector<int>> ...
Do you think compiler support is instantaneous for all platforms on all operating systems, retroactively, when the standard is published?
And all major compiler vendors have since learned that they need to be up to date with the standard ASAP, even before official publication when it is possible.
Advocating C++ < 11 is harmful to the community, given how bad it was at that time.
Suggesting that older versions of the compilers (which may be the latest available versions on certain systems) also do so is the "retroactive".
So no, they are not the same. But yes, they are both reasons why one can not just blindly start using the latest features from the latest standards.
Fixed that for you.
For all it's problems (some of which are being addressed in recent standard update , some not so much yet) it remains the best available tool for some domains. More's the pity.
I started with C++ a long time ago, but for whatever reason, kept getting out of it (for a few years) and then every time I'd get back in, I'd be surprised at the new stuff.
vector<vector<int>>
Prior to C++11, the code above would fail to compile. The lexer would see the final ">>" and assume it was the out-stream operator. This was such an annoying issue that they eventually changed the grammar so that the above would compile as expected.