I was browsing the web looking for simple yet fun programming challenges and crossed this one. I figured out how to reverse the string in place but I want it to read "blue is house the". I approached it in two ways for the heck of it. My idea was the second one, the first one I googled. I didn't know a simple rbegin() could do that, pretty neat.
I found the question here.http://www.techinterview.org Does anyone know of any other sites where I can find more?
Code:#include <iostream> #include <string> int main(int argc, const char * argv[]) { std::string phrase = "The house is blue."; for (auto it = phrase.rbegin(); it!=phrase.rend(); ++it) { std::cout<<*it; } std::cout<<"\n"; for (int i=0; i<phrase.length(); ++i) { std::cout<<phrase.at(phrase.length()-i-1); } return 0; }