#include <iostream> using namespace std; #include <string> #include <sstream> #include <cctype> #include <stack> int main() { string str; getline(cin, str); for (int i = 0; i <= str.size(); i++) { if (!isalpha(str[i])) { str[i] = ' '; } } istringstream is(str); string word; stack<string>s; while(is>>word){ s.push(word); } while(!s.empty()){ cout << s.top() << " "; s.pop(); } }
和HJ13比,主要是多了一项对特殊字符的检查,用cctype完成