Make a function that autodetects when unique

  2d-vector, algorithm, c++, qt, vector

I need to have a function in c++ that gets an element from a vector of strings as soon as the input is unique.

For example, my vector contains {"DELETE", "HELP", "GO FORWARD", "GO BACKWARDS"}.

If my input is then "H", the function should output "HELP" If the input is "H 55", it should ignore the 55 and still output "HELP".

However, when I add a new element "HELLO" to my vector, it should return "NOT UNIQUE".

I already tried a bunch of things, but I am not really getting anywhere.

I think a 2 dimensional vector would be a possible solution, but I have not been able to make it work:

["DELETE", "D"]
["DELETE", "DE"]
["DELETE", "DEL"]
["DELETE", "DELE"]
["DELETE", "DELET"]
["DELETE", "DELETE"]
["HELP", "HELP"]
["HELLO", "HELL"]
["HELLO", "HELLO"]
...

Source: Windows Questions C++

LEAVE A COMMENT