翻转句子中单词的顺序。
题目:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。
句子中单词以空格符隔开。为简单起见,标点符号和普通字母一样处理。
例如输入“I am a student.”,则输出“student. a am I”。
#include<iostream>
#include<algorithm>
#include<cctype>
#include<string>
using namespace std;
int main(void)
{
string str;
while (getline(cin, str))
{
reverse(str.begin(), str.end());
int count = 0;
for (int i = 0; i < (int)str.size();++i)
if (isblank(str[i]))
{
reverse(&str[count], &str[i]);
count = i + 1;
}
reverse(&str[count], &str[str.size()]);
cout << str << endl;
str.clear();
}
return 0;
}