题解 | #句子逆序#

句子逆序

https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3

#include <iostream>
using namespace std;
#include <string>
#include <vector>
int main() {
    string a;
    getline(cin,a);
    vector<string> v;
    int start=a.size()-1;
    int pos =0;
    int length =0;
    while(pos!=-1){
        string str="";
        pos = a.rfind(" ",start);
        length = start-pos;
        str = a.substr(pos+1,length);
        start = pos-1;
        v.push_back(str);
    }for(vector<string>::iterator it =v.begin();it!=v.end();it++){
        cout<<*it<<" ";
    }


    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务