In this HackerEarth Terrible Chandu problem solution Chandu is a bad student. Once his teacher asked him to print the reverse of a given string. He took three hours to solve it. The teacher got agitated at Chandu and asked you the same question. Can you solve it?


HackerEarth Terrible Chandu problem solution


HackerEarth Terrible Chandu problem solution.

#include <bits/stdc++.h>
using namespace std;
int main()
{
string s, s1;
int t;
for(cin >> t;t--;)
{
cin >> s;

// Reverse the string

// Solution 1

for(int i = 0;i < s.length() / 2;++i)
swap(s[i], s[s.length() - i - 1]);
cout << s << endl;

// Solution 2
/*
s1 = ""
for(int i = s.length() - 1;i >= 0;--i)
s1 += s[i];
cout << s1 << endl;

// Solution 3

reverse(s.begin(), s.end());
cout << s << endl;
*/
}
return 0;
}

Second solution

tc = int(raw_input())
while tc>0:
tc = tc - 1
s = raw_input()
print s[::-1]