将非字母字符替换为空格,使用istringstream、stack实现单词倒排

单词倒排

http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836

#include <bits/stdc++.h>
using namespace std;

int main() {
    stack<string> Stack;
    string s;
    getline(cin, s);
    
    for (char& c: s) {
        if (!isalpha(c)) {
            c = ' ';
        }
    }
    istringstream strm(s);
    string word;
    while (strm >> word) {
        Stack.push(word);
    }
    
    while (!Stack.empty()) {
        cout << Stack.top() << " ";
        Stack.pop();
    }
}
全部评论

相关推荐

评论
5
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务