fix C++ implementation

fixed below points:
  1. output was invalid. trailing " | " was output previously.
  2. std::random_shuffle() uses std::rand() which is obsolete.
     std::random_shuffle() will be deprecated officially in C++14.
Merge pull request #53 from rhysd/patch-1

Fixed C++ implementation