Reverse Iterators
Completed
Read a word and print it reversed using rbegin()/rend(), then print whether it is a palindrome using equal on the first half.
Input
n, then n words.
Output
n lines: reversed yes|no
Example
Input
3 level java noon
Output
level yes avaj no noon yes
Editor
C++
Hints
equal compares two ranges element by element.
Solution explanation
Reverse iterators walk a container backwards with the same interface.
Show solution
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string w;
cin >> w;
string r(w.rbegin(), w.rend());
bool pal = equal(w.begin(), w.begin() + w.size() / 2, w.rbegin());
cout << r << " " << (pal ? "yes" : "no") << "\n";
}
return 0;
}