题解 | #句子逆序#
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main() {
string str;
string newstr;
string word;
char c;
while(getline(cin,str)){
while(!str.empty()){
c = str.back();
if(c!=' '){
word.insert(0,1,c);
}
else{
word.push_back(' ');
newstr += word;
word.clear();
}
str.pop_back();
}
newstr.insert(newstr.size(),word);
cout << newstr << endl;
newstr.clear();
}
return 0;
}
查看11道真题和解析