题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include<iostream>
#include<stack>
using namespace std;
int main() {
string text;
getline(cin, text);
stack<string> sta;
string str;
for(int i=0;i<text.length();i++) {
if(text[i] != ' ') {
str += text[i];
}else {
sta.push(str);
str = "";
}
if(i == text.length()-1) {
sta.push(str);
}
}
while(!sta.empty()) {
if(sta.size()==1)
cout<<sta.top();
else
cout<<sta.top()<<" ";
sta.pop();
}
cout<<endl;
return 0;
}
传音控股公司福利 356人发布