题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include <iostream>
#include <string>
#include <stack>
using namespace std;
int main() {
string s;
while (getline(cin, s)) { // 注意 while 处理多个 case
int n = s.length();
stack<char> stk;
for (int i = n - 1; i >= 0; i--) {
int Ascii = s[i] - 'A';
int ascii = s[i] - 'a';
if ((Ascii >= 0 && Ascii < 26) || (ascii >= 0 && ascii < 26)) {
stk.push(s[i]);
} else if (!stk.empty()) {
while (!stk.empty()) {
cout << stk.top();
stk.pop();
}
cout << " ";
}
}
while (!stk.empty()) {
cout << stk.top();
stk.pop();
}
}
}
// 64 位输出请用 printf("%lld")