Computer Science, asked by asarkarhiya, 2 months ago

write a program to input a sentence and count the no. of repetitive letters​

Answers

Answered by venkateshpatil42
0

Answer:

what is free fire?.. and which country has most downloads of it7359042520 Tap on a clip to paste it in the text box.Touch and hold a clip to pin it. Unpinned clips will be deleted after 1 hour.

Answered by sukki120599
0

Answer:

This is the algorithm for the question

  1. Define a string or take input.
  2. Two loops will be used to find the duplicate characters. Outer loop will be used to select a character and initialize variable count by 1.
  3. Inner loop will compare the selected character with rest of the characters present in the string.
  4. If a match found, it increases the count by 1 and set the duplicates of selected character by '0' to mark them as visited.
  5. After inner loop, if count of character is greater than 1, then it has duplicates in the string.

Explanation:

string =input("Enter your string");  

 

print("Duplicate characters in a given string: ");  

#Counts each character present in the string  

for i in range(0, len(string)):  

   count = 1;  

   for j in range(i+1, len(string)):  

       if(string[i] == string[j] and string[i] != ' '):  

           count = count + 1;  

           #Set string[j] to 0 to avoid printing visited character  

           string = string[:j] + '0' + string[j+1:];  

 

   #A character is considered as duplicate if count is greater than 1  

   if(count > 1 and string[i] != '0'):  

       print(string[i]);  

Similar questions