题解 | #倒置字符串#

倒置字符串

https://www.nowcoder.com/practice/ee5de2e7c45a46a090c1ced2fdc62355

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

int main() {
    string str;
    getline(cin, str);
    reverse(str.begin(),str.end());
    int start = 0;
    for(int i = 0; i <= str.length(); i++){
        if(str[i] ==' ' || i == str.length()){
            reverse(str.begin() + start, str.begin() + i);
            start = i + 1;
        }
    }
    cout << str;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

玉无心❤️:发照片干啥 发简历啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务