典型的字符串处理。。
#include <string>
#include <iostream>
using namespace std;
int main()
{
int N;
cin >> N;
cin.get();
for (int i = 0; i < N; i++)
{
string tempStr;
getline(cin, tempStr);
if (i > 0)
{
cout << endl;
}
int nStrNum;
cin >> nStrNum;
cin.get();
while (nStrNum--)
{
string str;
getline(cin, str);
for (int begin = 0; begin < str.length(); )
{
while (begin < str.length()
&& (str[begin] == ' ' || str[begin] == '\t'))
{
begin++;
}
if (begin == str.length())
{
break;
}
int end = begin;
while (end < str.length()
&& (str[end] != ' ' && str[end] != '\t'))
{
end++;
}
for (int tempIndex = end - 1; tempIndex > begin; begin++, tempIndex--)
{
char temp = str[begin];
str[begin] = str[tempIndex];
str[tempIndex] = temp;
}
begin = end;
}
cout << str << endl;
}
}
return 0;
}