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
- Given a sequence of words, print all anagrams together using STL
- Print all possible words from phone digits
- Given a sequence of words, print all anagrams together | Set 2
- Given a sequence of words, print all anagrams together | Set 1
- Print all valid words that are possible using Characters of Array
- Print number of words, vowels and frequency of each character
- Java ArrayList to print all possible words from phone digits
- Print all words matching a pattern in CamelCase Notation Dictonary
- Reverse words in a given string
- Count words in a given string
- Shortest substring of a string containing all given words
- Reverse String according to the number of words
- Count words present 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.