Given a string str of size N, the task is to find the sum of all ASCII values of the characters which are present at prime positions.
Input: str = “abcdef”
‘b’, ‘c’ and ‘e’ are the only characters which are
at prime positions i.e. 2, 3 and 5 respectively.
And sum of their ASCII values is 298.
Input: str = “geeksforgeeks”
Approach: An efficient approach is to traverse through the whole string and find if the particular position is prime or not. If the position of the current character is prime then add the ASCII value of the character to the answer.
Below is the implementation of the above approach:
- Count characters in a string whose ASCII values are prime
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Program to find the product of ASCII values of characters in a string
- Program to find the XOR of ASCII values of characters in a string
- Average of ASCII values of characters of a given string
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k
- Map function and Dictionary in Python to sum ASCII values
- Minimize ASCII values sum after removing all occurrences of one character
- Count the number of words having sum of ASCII values less than and greater than k
- Split a given string into substrings of length K with equal sum of ASCII values
- Program to print characters present at prime indexes in a given string
- Remove characters from the first string which are present in the second string
- Program to find the largest and smallest ASCII valued characters in a string
- Count Numbers in Range with difference between Sum of digits at even and odd positions as Prime
- Sums of ASCII values of each word in a sentence
- Convert a string to hexadecimal ASCII values
- Check if a string contains only alphabets in Java using ASCII values
- Print each word in a sentence with their corresponding average of ASCII values
- Count of alphabets whose ASCII values can be formed with the digits of N
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.