We are given a sentence. Our task is to print all funny words/strings in that sentence.
What is a funny word ?
Reverse the given string. Iterate through each character of that string, compare the absolute difference in the ASCII values of the characters at positions 0 and 1, 1 and 2, 2 and 3 and so on to the end. If the list of absolute differences is the same for both strings, they are funny otherwise not.
Input : HKMNPS Output : Yes Let r be the reverse of original string s s = "HKMNPS" r = "SPNMKH" |H-K| = 3 = |S-P| |K-M| = 2 = |P-N| |M-N| = 1 = |N-M| |N-P| = 2 = |M-K| |P-S| = 3 = |K-H| Since each comparison is equal so given string is funny Input : bdwy Output : No
NOTE : Every palindrome string is a funny string but not vice-versa.
The idea is to split string into words. For every word, traverse it from both ends and compare differences between adjacent characters.
Arora us malayalam bdwy
- Print words of a string in reverse order
- Check if the given string of words can be formed from words present in the dictionary
- Print all possible words from phone digits
- Program to print the given digit in words
- Given a sequence of words, print all anagrams together | Set 2
- Given a sequence of words, print all anagrams together using STL
- Given a sequence of words, print all anagrams together | Set 1
- Print all possible combinations of words from Dictionary using Trie
- Print all valid words that are possible using Characters of Array
- Java ArrayList to print all possible words from phone digits
- Print number of words, vowels and frequency of each character
- Print all words matching a pattern in CamelCase Notation Dictonary
- Reverse words in a given string
- Count words in a given string
- Reverse String according to the number of words
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.