本题较为简单。
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int main() {
string s;
getline(cin, s, '\n');
vector<string> str;
string temp;
for (int i = 0; i < s.size(); i++) {
if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')) {
temp = temp + s[i];
} else if (!temp.empty()) {
str.push_back(temp);
temp.clear();
} else {
continue;
}
}
str.push_back(temp);
for (vector<string>::reverse_iterator iter = str.rbegin(); iter != str.rend(); iter++) {
cout << *iter << " ";
}
return 0;
}
京公网安备 11010502036488号