/* 解题思路:栈 注意:将单词整个整个放入栈中 */

#include #include #include using namespace std; int main() { string str; string word; stack stk; getline(cin, str); //将单词逐个放入栈中 for(int i=0; i<str.size(); i++) { if(str[i] != ' ') word += str[i]; else { stk.push(word); word = ""; } if(i == str.size()-1) stk.push(word); } //输出 while(!stk.empty()) { cout << stk.top() << " "; stk.pop(); } cout << endl; return 0;

}