C++ Program to find the first repeated character in the string is given below. In this i used and unordered_map <char,int> to store the count of the every character of the string.. Approach is simple we traverse the string and store the count of each character of string and check whether count of the current element is more than one or not.. If count is more than 1 then we break and that character of the string will be the first repeated character. If count of every character of the string remains 1till the end of string traversal then no character is repeated.

Example:      python
Ans:               No character is repeated
Example:      Java
Ans:                a
Example:      Austrailia
Ans:                i

PROGRAM:

 


#include <stdio.h>
#include <string.h>
#include <unordered_map>
using namespace std;

int main()
{
   std::unordered_map <char,int> m;
   char string[100];
   printf("\n\nEnter the string: \n");
   scanf("%s",string);
   int flag=0;
   char c;
   for(int i=0;i<strlen(string);i++)
   {
         m[string[i]]++;
         if(m[string[i]]>1)
         {
             flag=1;
             c=string[i];
             break;
         }
   }
   if(flag==0)
   {
         printf("\nNo repetation");
   }
   else
   {
         printf("\n\nFirst Repeating character is: %c",c);
   }
      return 0;
}

OUTPUT: