#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main() {
string str;
int i = 0; //访问字符数组的下标
int count = 0;
cout << "请输入一句话:" << endl;
getline(cin, str);
while (str[i]) { //跳过前面的空格
while (str[i] == ' ') i++; //该循环结束后,str[i]是下一个单词的第一个字母
int j = i;
while (str[j] && str[j] != ' ') j++; //该循环结束后,str[j]是这个单词后面的下一个位置
//逆转这个单词
for (int k1 = i, k2 = j - 1; k1 < k2; k1++, k2--) {
char tmp = str[k1];
str[k1] = str[k2];
str[k2] = tmp;
}
i = j;
}
for (int k1 = 0, k2 = i - 1; k1 < k2; k1++, k2--) {
char tmp = str[k1];
str[k1] = str[k2];
str[k2] = tmp;
}
cout << str << endl;
system("pause");
return 0;
}