While I still feel this is a duplicate, the thought process for solving this would be this:
- Write a function that returns true for alphabet characters (a-z and A-Z), and false otherwise.
- Start at the beginning of the string
- Find the next alphabet character, note its location (start)
- Find the next non-alphabet character, note its location (end)
- Reverse the characters in the range [start, end)
- Repeat steps 3-5 until the end of the string
All of this becomes very easy when you use std::string
and algorithms like std::reverse
instead of using raw arrays and custom. Since you are allowed to use std::cin
and std::cout
(<iostream>
), the argument against using <string>
is a silly one.