We are given a sentence of english language(can also contain digits), we need to compute and print the sum of ASCII values of characters of each word in that sentence.
Input : GeeksforGeeks, a computer science portal for geeks Output : Sentence representation as sum of ASCII each character in a word: 1361 97 879 730 658 327 527 Total sum -> 4579 Here, [GeeksforGeeks, ] -> 1361, [a] -> 97, [computer] -> 879, [science] -> 730 [portal] -> 658, [for] -> 327, [geeks] -> 527 Input : I am a geek Output : Sum of ASCII values: 73 206 97 412 Total sum -> 788
- Iterate over the length of the string and keep converting the characters to their ASCII
- Keep adding up the values till the end of sentence.
- When we come across a space character, we store the sum calculated for that word and set the sum equal to zero again.
- Later, we print elements
Sum of ASCII values: 1317 97 879 730 658 327 495 Total sum -> 4503
The complexity of the approach is
- Print each word in a sentence with their corresponding average of ASCII values
- Print given sentence into its equivalent ASCII form
- Convert the ASCII value sentence to its equivalent string
- Check if a word is present in a sentence
- Program to replace a word with asterisks in a sentence
- Print longest palindrome word in a sentence
- Program for length of the longest word in a sentence
- Java program to count the characters in each word in a given sentence
- Average of ASCII values of characters of a given string
- Map function and Dictionary in Python to sum ASCII values
- Convert a string to hexadecimal 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
- Check if a string contains only alphabets in Java using ASCII values
- Count characters in a string whose ASCII values are prime
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.