将非字母字符替换为空格,使用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();
}
}
查看4道真题和解析