题解 | #句子逆序#
句子逆序
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")
海康威视公司福利 1154人发布
查看12道真题和解析