shortened C++ version with /u/bugrit's help

Improvements over my code by /u/bugrit, see: http://www.reddit.com/r/programming/comments/2btrvt/gal/cj93awc

I like this because it is even shorter. I think this makes this C++ solution one of the shortest, when you ignore the languages where it's a one liner. 5 LOC, no global state, non-hacky standard C++ 98.