题解 | #单词倒排#

单词倒排

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")

全部评论

相关推荐

自来熟的放鸽子能手面...:等捞就好了,你这种情况被捞的概率挺大的
投递字节跳动等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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