C++ code to check uniqueness of every elements in a string

Suman Barik
0
//C++ code to check uniqueness of every elements in a string #include using namespace std; bool is_unique(string str){ int n = str.length(); for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ if(str[i] == str[j]){ return false; } } } return true; } int main(){ string str; cout << "Type your string here: "; getline(cin, str); if(is_unique(str)){ printf("True"); } else{ printf("False"); } return 0; } //Code contributed by Suman Barik
Tags

Post a Comment

0Comments
Post a Comment (0)