String S which is a palindrome is passed as the input. But just one alphabet A is missing in S. The program must print the missing alphabet A.
Note: The FIRST alphabet of S will always be present.
Input Format:
The first line contains S.
Output Format:
The first line contains the missing alphabet A.
Boundary Conditions:
The length of the input string S is between 3 to 100.
The FIRST alphabet of S will always be present.
Example Input/Output 1:
Input:
malayaam
Output:
l
Example Input/Output 2:
Input:
abcddcb
Output:
a
Program
#include<stdio.h>
#include <stdlib.h>
int main()
{
char S[100];
int i,j,a;
scanf("%s",S);
a=strlen(S);
if (S[0]!=S[a-1])
{
printf("%c",S[0]);
exit(0);
}
for(i=0,j=a-1;i<a/2;i++,j--)
{
if (S[i]!=S[j])
{
if (S[i+1]==S[j])
printf("%c",S[i]);
else
printf("%c",S[j]);
break;
}
}
}
OUTPUT
malayaam
l
Input Format:
The first line contains S.
Output Format:
The first line contains the missing alphabet A.
Boundary Conditions:
The length of the input string S is between 3 to 100.
The FIRST alphabet of S will always be present.
Example Input/Output 1:
Input:
malayaam
Output:
l
Example Input/Output 2:
Input:
abcddcb
Output:
a
Program
#include<stdio.h>
#include <stdlib.h>
int main()
{
char S[100];
int i,j,a;
scanf("%s",S);
a=strlen(S);
if (S[0]!=S[a-1])
{
printf("%c",S[0]);
exit(0);
}
for(i=0,j=a-1;i<a/2;i++,j--)
{
if (S[i]!=S[j])
{
if (S[i+1]==S[j])
printf("%c",S[i]);
else
printf("%c",S[j]);
break;
}
}
}
OUTPUT
malayaam
l
No comments:
Post a Comment