#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
getline(cin, str);
int point = str.size()-1;
int right = str.size();
int left;
bool flag = true;
unsigned int len = str.size();
for (int i = len - 1; i >= 0; i--)
{
if (str[i] != ' ')
{
flag = false;
point--;
continue;
}
if (!flag)
{
flag = true;
left = point;
point++;
while (point != right)
{
cout << str[point];
point++;
}
cout << " ";
point = left - 1;
right = left;
}
else
{
right = point;
point--;
}
}
point++;
if (point != right)
{
while (point != right)
{
cout << str[point];
point++;
}
cout << " ";
}
cout <<'\b';
return 0;
}
后来想想可以这么做