Given a string of lower and uppercase characters, the task is to find that how many characters are at same position as in English alphabet.
Input: ABcED Output : 3 First three characters are at same position as in English alphabets. Input: geeksforgeeks Output : 1 Only 'f' is at same position as in English alphabet Input : alphabetical Output : 3
For this we can have simple approach:
1) Initialize result as 0. 2) Traverse input string and do following for every character str[i] a) If 'i' is same as str[i] - 'a' or same as str[i] - 'A', then do result++ 3) Return result
This article is contributed by Sahil Chhabra. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Remove characters from the first string which are present in the second string
- Print list items containing all characters of a given word
- Find the smallest window in a string containing all characters of another string
- Length of the longest substring without repeating characters
- Print all permutations with repetition of characters
- Interleaving of two given strings with no common characters
- Count words in a given string
- String matching where one string contains wildcard characters
- Find the first non-repeating character from a stream of characters
- Rearrange a string so that all same characters become d distance away
- Given a sorted dictionary of an alien language, find order of characters
- Given a binary string, count number of substrings that start and end with 1.
- Find the longest substring with k unique characters in a given string
- Reverse an array without affecting special characters
- Find all strings formed from characters mapped to digits of a number