For the given a string S consists of a stream of
characters not in predefined order. Write a
program to find the first non-repeating
character in a string S.
Input Format
h
First line contains input string, less than or equal
to buffer size N=20
Output Format
Output contains only single non-repeating
character from a strings
If string contains all repetitive characters, pri
"Exceptional String
If string length is greater than 20, print Wrong
Input"
Constraints
1 greater than = N greater than =20
sample input 1:
sample input 2:
sample input 3:
Answers
Answer:
Input: "geeksforgeeks"
Explanation:
Step 1: Construct a character count array
from the input string.
....
count['e'] = 4
count['f'] = 1
count['g'] = 2
count['k'] = 2
……
Step 2: Get the first character who's
count is 1 ('f').
Explanation:
Answer:
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,len,flag;
char str1[20];
gets(str1);
len = strlen(str1);
if(len>20)
{
printf("Wrong Input");
}
for(i=0;i<len-1;i++)
{
flag=1;
for(j=0;j<len;j++)
{
if(str1[i]==str1[j] && i!=j)
{
flag=0;
break;
}
}
if(flag != 0)
{
printf("%c",str1[i]);
break;
}
}
if(flag == 0)
{
printf("Exceptional String");
}
return 0;
}
Explanation: