Implement an algorithm to determine if a string has all unique characters. The user will enters a sentence and your job is to determine if there is repeating letter in the sentence.
#include <iostream>
#include <sting>
usingnamespace std;
int main()
{
bool isUnique(string);
int main(){
bool uniq;
string a;
cout << "Please input a string, not a very long one...."<< endl;
getline(cin, a);
uniq = isUnique(a);
if (uniq == true)
{
cout << "The string has no repeatations." <<endl;
}else{
cout << "The characters in the string are not unique." <<endl;
}
return EXIT_SUCCESS;
}
bool isUnique(string str){
int len = strlen(str);
bool uniq = true;
for (int i = 0; i <= len; ++i)
{
for (int j = i+1; j <= len; ++j)
{
if (str[j] == str[i])
{
uniq = false;
}
}
}
return uniq;
string char;
cout << " Please enter a string of characters: "
getline(cin,char)
I need help on making a nested loop and remove all the spaces in the string using erase function from string class. Also, I want to know if there are better soulution?