用栈这题就很好写了,并且代码很简洁。
inline void solved() {
string s;
stack<string>st;
while (cin >> s) st.push(s); //利用cin会屏蔽空格的特性
while (!st.empty()) {
cout << st.top();
st.pop();
if (!st.empty()) cout << ' '; // 控制格式,题目要求两个单词之间要有空格
}
}
完结撒花!!!