#include <iostream>
#include <vector>
#include <string>
std::string checkUnique(const std::string& searchString, const std::vector<std::string>& inputVector)
{
int count = 0;
std::string foundString;
for(const std::string &element: inputVector)
{
if(element.at(0) == searchString.at(0))
{
foundString = element;
++count; //increment count
}
}
if(count == 0)
{
return "NOT FOUND";
}
else if(count == 1)
{
return foundString;
}
else
{
return "NOT UNIQUE";
}
}
int main()
{
std::vector<std::string> inputVector{"DELETE", "HELP", "GO FORWARD", "GO BACKWARDS"};
std::string searchString = "H";
//call the function for different cases
std::cout << checkUnique(searchString, inputVector) <<std::endl;;//prints HELP
std::cout << checkUnique("H", inputVector) << std::endl; //prints HELP
std::cout << checkUnique("H 55", inputVector) << std::endl; //prints HELP
//add "HELLO" into the vector
inputVector.push_back("HELLO");
std::cout << checkUnique("H", inputVector) << std::endl; //prints NOT UNIQUE
std::cout << checkUnique("H 55", inputVector) << std::endl; //prints NOT UNIQUE
return 0;
}