题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include <iostream> #include <sstream> #include <vector> #include <string> using namespace std; int main() { string str; getline(cin, str);//str存入整行输入 for (char &x : str) { if (!isalpha(x))//输入中不是字母的字符替换成‘ ’空格 { x = ' '; } } vector<string> vs; string tmp; istringstream iss(str); while (iss >> tmp) { vs.push_back(tmp);//将单词提取出来放入vs容器中 } //按格式逆序输出容器中的单词,注意添加空格 for (int i = vs.size() - 1; i >= 0; --i) { cout << vs.at(i) << ' '; } return 0; } // 64 位输出请用 printf("%lld")