解析:
字符串反转。。
输入多个用例
每个用例都当做是字符串
遍历字符串,遇到空格即将当前位置的前一个字符到上个空格(如果有的话)之间的子字符串翻转输出,再输出空格,
遇到结束符‘\0’即将当前位置的前一个字符到上个空格(如果有的话)之间的子字符串翻转输出,再输出换行
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n;
string s;
cin >> n;
getchar();
while (n--)
{
getline(cin, s);
int k = s.length();
int tempz =-1,tempy=-1;
for (int i = 0; i <= k; i++)
{
if (s[i] == ' ')
{
tempz = tempy+1;
tempy = i;
for (int j = tempy-1; j >= tempz; j--)
{
cout << s[j];
}
cout << " ";
}
if (s[i]=='\0')
{
tempz = tempy+1;
tempy = i;
for (int j = tempy-1; j >= tempz; j--)
{
cout << s[j];
}
cout << endl;
}
}
}
return 0;
}