传送门:点击打开链接
#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;
}
字符串逆序输出
本文介绍了一个简单的C++程序,该程序能够实现字符串的逆序输出功能。通过使用栈数据结构来辅助实现,程序首先将输入的字符逐个压入栈中,再依次弹出并输出这些字符,从而达到逆序输出的效果。
6592

被折叠的 条评论
为什么被折叠?



