Given a string of alphanumeric characters, the task is to check whether the average character of the string is present or not. Average character refers to the character corresponding to the ASCII value which is the floor of the average value of the ASCII values of all characters in the string.
Input: abcdef Output: d Yes Explanation: string = "abcdef" ASCII values of a = 97, b=98, c=99, d=100, e=101, f=101 Sum of these values is 597 Average is 99.5 ~ 100 Character of ASCII value 100 = d Hence d is present in the string. Input: MNFGH Output: J No
Approach: The approach to solve this problem is very simple. It can be solved in the following steps:
- Find the sum of ASCII values of all the characters from the given string.
- Find the average of the ASCII value as average = (sum / numberOfCharacters)
- Get the character of this average ASCII value. Print this character
- Check if this character is present in the string or not. Print Yes or No accordingly.
Below is the implementation of the above approach:
- Find the character in first string that is present at minimum index in second string
- Find repeated character present first in a string
- Python | Check if a Substring is Present in a Given String
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Check if both halves of the string have at least one different character
- Check if a two character string can be made using given words
- Python | Check order of character in string using OrderedDict( )
- Check if max occurring character of one string appears same no. of times in other
- Check if the frequency of any character is more than half the length of the string
- Check if the given string of words can be formed from words present in the dictionary
- Check input character is alphabet, digit or special character
- Find the longest sub-string which is prefix, suffix and also present inside the string
- Find the longest sub-string which is prefix, suffix and also present inside the string | Set 2
- Modify the string such that every character gets replaced with the next character in the keyboard
- Replace every character of string by character whose ASCII value is K times more than it
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.