Created
December 17, 2013 15:45
-
-
Save KorbenC/8006991 to your computer and use it in GitHub Desktop.
Checks if a string is unique
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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