Sample Input
3 olleh !dlrow m'I morf .udh I ekil .mca
Sample Output
hello world! I'm from hdu. I like acm.HintRemember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
#include <iostream>
#include<string>
#include <algorithm>
using namespace std;
int main()
{
string str;
int begin,j,n;
while (cin>>n)
{
getchar();
while (n--)
{
getline(cin,str);
j = 0;
begin = 0;
while(str.find(' ',j)!=string::npos)
{
reverse(str.begin()+j,str.begin()+str.find(' ',j)); //这里的第二个参数不用再加J
j = str.find(' ',j)+1;
}
reverse(str.begin()+j,str.end()); //最后一个单词(没有空格情况)
cout<<str<<endl;
}
}
return 0;
}