Given a string ‘str’, two integers ‘k’ and ‘p’. The task is to count all the sub-strings of ‘str’ having exactly ‘k’ characters that have ASCII value greater than ‘p’.
Input: str = “abcd”, k=2, p=98
Only the characters ‘c’ and ‘d’ have ASCII values greater than 98,
And, the sub-strings containing them are “abcd”, “bcd” and “cd”.
Input: str = “sabrcd”, k=5, p=80
Approach: We just need to iterate over all indices and take all possible length sub-strings and then just check whether the sub-string has exactly ‘k’ characters that have ASCII value greater than ‘p’.
Typecasting a character to int will give us it’s ASCII value i.e.
int ascii = (int) char.
Below is the implementation of the above approach:
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k
- Count of alphabets having ASCII value less than and greater than k
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Count the number of words having sum of ASCII values less than and greater than k
- Average of ASCII values of characters of a given string
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Program to find the XOR of ASCII values of characters in a string
- Count characters in a string whose ASCII values are prime
- Count pairs of characters in a string whose ASCII value difference is K
- Count number of substrings with numeric value greater than X
- Find the sum of the ascii values of characters which are present at prime positions
- Program to find the product of ASCII values of characters in a string
- Count substrings with same first and last characters
- Count of substrings whose Decimal equivalent is greater than or equal to K
- Program to find the largest and smallest ASCII valued characters in a string
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.