ZOJ Problem Set - 1151
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151
#include <iostream>
#include <string>
using namespace std;
int main()
{
int block, loop, i, j;
string input, output;
int sIdx, eIdx;
cin >> block;
while(block--) {
cin >> loop;
getline(cin, input);
while(loop--) {
getline(cin, input);
input.append(" ");
output = "";
sIdx = 0;
eIdx = 0;
for(i=0;i<input.size();i++) {
if(' ' != input[i]) {
eIdx++;
} else {
for(j=eIdx;j>sIdx;j--) {
output.append(input, j-1, 1);
}
output.append(" ");
eIdx++;
sIdx = eIdx;
}
}
output.erase(output.end()-1);
cout << output << endl;
}
if(block) cout << endl;
}
return 0;
}