codewars Reversed Words
include <string>
#include <vector>
std::string reverse_words(const std::string& str) {
std::stringstream ss(str);
std::vector<std::string>mp;
std::string word;
std::string result;
while(ss>>word){
mp.push_back(word);
}
std::reverse(std::begin(mp), std::end(mp));
for(auto it = mp.begin(); it != mp.end(); ++it){
//空格问题
/*for (每个单词 it) {
if (不是第一个) result += " ";
result += *it;
}*/
if(it != mp.begin()) result += " ";
result += *it;
}
return result;
}

浙公网安备 33010602011771号