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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print each word in a sentence with their corresponding average of ASCII values
- Convert the ASCII value sentence to its equivalent string
- Print given sentence into its equivalent ASCII form
- Check if a word is present in a sentence
- Find the word with most anagrams in a given sentence
- Program for length of the longest word in a sentence
- Program to replace a word with asterisks in a sentence
- Print longest palindrome word in a sentence
- Java program to count the characters in each word in a given sentence
- Convert a string to hexadecimal ASCII values
- Map function and Dictionary in Python to sum ASCII values
- Average of ASCII values of characters of a given string
- Check if a string contains only alphabets in Java using ASCII values
- Program to find the XOR of ASCII values of characters in a string
- 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
- Count characters in a string whose ASCII values are prime
- Find the sum of the ascii values of characters which are present at prime positions
- Split a given string into substrings of length K with equal sum of ASCII values
- Program to find the product of ASCII values of 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.