Skip to content

Instantly share code, notes, and snippets.

@KorbenC
Created December 17, 2013 15:45
Show Gist options
  • Save KorbenC/8006991 to your computer and use it in GitHub Desktop.
Save KorbenC/8006991 to your computer and use it in GitHub Desktop.
Checks if a string is unique
#include<iostream>
#include<string>
using namespace std;
int main()
{
char str[80];
bool isUnique = true;
cout << "Enter a word: ";
cin >> str;
int length = strlen(str);
for(int i = 0; i < length; i++)
{
str[i] = tolower(str[i]);
}
for(int i = 0; i < length; i++)
{
for(int j= i+1; j < length; j++)
{
if(str[i] == str[j])
{
isUnique = false;
break;
}
}
}
if(isUnique == true)
{
cout << str << " is unique." << endl;
}
else
{
cout << str << " is not unique." << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment