题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include <iostream>
#include <string>
using namespace std;
int main() {
string str;
getline(cin, str);
string word;
string ans;
for(int i = 0; i < str.length(); i++){
if((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z')){
word += str[i];
if(i == str.length() - 1) ans = word + " " + ans;
}
else{
if(ans.empty()) ans += word;
else ans = word + " " + ans;
word.clear();
}
}
cout << ans << endl;
}
SHEIN希音公司福利 350人发布