cpp implementation of Substring with Concatenation of All Words