题解 | #句子逆序#
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include <cstdio> #include <functional> #include <iostream> #include <queue> #include <string> #include <unordered_map> #include <vector> using namespace std; using LL = long long; int main(){ string s; while (getline(cin, s)){ int n=s.size(); int l=0; for(int i=0; i<n; ++i){ if (s[i]==' '){ reverse(s.begin()+l, s.begin()+i); l=i+1; } } reverse(s.begin()+l, s.end()); reverse(s.begin(), s.end()); cout<<s<<endl;; } return 0; }