Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
#include<iostream>
#include<string>
using namespace std;
void main()
{
int T;
while (cin>>T)
{
getchar();
for (int i = 0; i < T; i++)
{
string str;
getline(cin, str);
int end = 0,top = 0;
while (str[end] != '\0')
{
if (str[end]==' ')
{
for (int i = end-1; i >=top; i--)
{
cout << str[i];
}
cout << str[end];
top = end + 1;
}
end++;
}
if (str[end]=='\0')
{
for (int i = end-1; i >=top-1; i--)
{
cout << str[i];
}
}
cout << endl;
}
}
}