传送门:点击打开链接
#include <iostream>
#include <sstream>
#include <stack>
#include <cctype>
using namespace std;
int main(){
char ch;
stack<char> sentance;
stack<char> word;
int i = 0;
bool isfirst = false;
while(scanf("%c", &ch) && ch != '\n'){
sentance.push(ch);
}
while(!sentance.empty()){
while(!sentance.empty()&&!isalpha(sentance.top()))
sentance.pop();
while(!sentance.empty()&&isalpha(sentance.top())){
word.push(sentance.top());
sentance.pop();
}
if(word.empty()) isfirst = false;
if(isfirst) cout << " ";
isfirst = true;
while(!word.empty()){
cout << word.top();
word.pop();
}
}
return 0;
}