178k views
3 votes
Assign True to the variable has_dups if the string s1 has any duplicate character (that is if any character appears more than once) and False otherwise.

User Kamilos
by
7.9k points

1 Answer

1 vote

Answer:

#include <iostream>

using namespace std;

int main()

{

string s;

cin>>s; //reading string

int i,j;

bool has_dups=false;

int n= s.length();

for(i=0;i<n;i++) //to check for duplicate characters

{

for(j=0;j<n;j++)

{

if(j!=i && s[i]==s[j]) //to check if it is matched with itself

{

has_dups=true; //if true no need to check others

break;

}

}

}

cout<<has_dups;

return 0;

}

OUTPUT :

California

1

Step-by-step explanation:

Above program finds if a character repeat itself in the string entered by user.

User Adaxa
by
8.7k points