题解 | #单词倒排#

单词倒排

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

#include <iostream>
#include <string>
using namespace std;

int main() {
    string str;
    getline(cin, str);
    string word;
    string ans;
    for(int i = 0; i < str.length(); i++){
        if((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')){
            word += str[i];
            if(i == str.length() - 1) ans = word + " " + ans;
        }
        else{
            if(ans.empty()) ans += word;
            else ans = word + " " + ans;
            word.clear();
        }
    }
    cout << ans << endl;

}

全部评论

相关推荐

2025-12-15 11:27
门头沟学院 Java
哇哇的菜鸡oc:所有人不要理会,就好了,后面他就知道怎么回事了,只能说有的时候市场都是被宰的人搞坏的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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