Given a string str consisting of a sentence, the task is to reverse every word of the sentence except the first and last character of the words.
Input: str = “geeks for geeks”
Output: gkees for gkees
Input: str = “this is a string”
Output: tihs is a snirtg
Approach: Break the string into words using strtok(), now for every word take two pointers i and j pointing to the second and the second last character of the string respectively. Swap these characters then increment i and decrement j. Repeat these steps while i < j.
Below is the implementation of the above approach:
gkees for gkees
- Capitalize the first and last character of each word in a string
- Print the first and last character of each word in a String
- Remove the first and last character of each word in a string
- Print last character of each word in a string
- Reverse each word in a linked list node
- Replace every character of string by character whose ASCII value is K times more than it
- Find a string such that every character is lexicographically greater than its immediate next character
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Map every character of one string to another such that all occurrences are mapped to the same character
- Most frequent word in first String which is not present in second String
- String containing first letter of every word in a given string with spaces
- Replace every character of a string by a different character
- Create a new string by alternately combining the characters of two halves of the string in reverse
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest string formed by appending a character from the first K characters of a given 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 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.