C++,用字符串做容器的解题思路。
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str, temp, dst;
getline(cin, str);
for (char c : str)
{
if (c != ' ')
temp += c; //左右拼接有差异的
else
{
dst = ' ' + temp + dst;
temp.clear(); //注意清除容器
}
//判断c是否为最后一个字符
if ((dst.length() + temp.length()) == str.length())
{
dst = temp + dst;
}
}
cout << dst;
return 0;
}

京公网安备 11010502036488号