to find a unique set of substring in cpp