题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include <iostream>
#include <stack>
#include <string>
using namespace std;
class stack<string> st;
int check(){
string s;
s=st.top();
st.pop();
int t=0;
for(int i=0;i<s.length();i++){
if (((s[i]>='a')&&(s[i]<='z'))||((s[i]>='A')&&(s[i]<='Z'))) {
}else {
st.push(s.substr(t,i-t));
t=i+1;
}
}
if (t==0) {
st.push(s);
}else {
st.push(s.substr(t,s.length()-t));
}
return 0;
}
int main() {
string s;
char c;
while (cin >> s) {
st.push(s);
}
while (!st.empty()) {
check();
cout<<st.top()<<' ';
st.pop();
}
}
叮咚买菜工作强度 238人发布