First Repeating Character From Last

 

                          First Repeating Character

 

A string S is passed as the input. S has at least one repeating character. The program must print the first repeating character C from the last.
Input Format:
The first line contains S.
Output Format:
The first line contains C.
Boundary Conditions:
Length of S will be from 3 to 100.
Example Input/Output 1:
Input:
abcdexyzbwqpooplj
Output:
p

Code:

#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv)
{
char str[100];
fgets(str,100,stdin);
int i,j,flag=0;
char temp;
for(i=strlen(str)-1;i>=0;i--)
{
    temp=str[i];
    for(j=i-1;j>=0;j--)
    {
        if(temp==str[j])
            {
                cout<<temp;
                flag=1;
                break;
            }
    }
    if(flag==1)
        break;
}
}

Please do comment If u have any Queries!

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *