The program must accept a string value S contains only alphabets as the input. The program must print an alphabet from S which has occurred first in the alphabetical order as the output.
Examples :
Input : qwerty Output : e Explanation : In the word qwerty, the character 'e' has occurred first in the alphabetical order.Hence the output is e. Input : zxsvwu Output : s
Simple Approach :
Assume that the first character in the string is the alphabetically first character
Traverse through the string and replace the character which is alphabetically first
Print the character.
Implementation :
#include<stdio.h>
#include <string.h>
int main()
{
char s[100];
scanf("%s",s);
// assume the first character is alphabetically first
char m = s[0];
for(int i=1;i<strlen(s);i++)
{
//if the current character is small then assume it as minimum
if(s[i]<m)
m = s[i];
}
printf("%c",m);
return 0;
}
#print the first character in the sorted list of characters
print(sorted(list(input().strip()))[0])