题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
include<bits/stdc++.h>
using namespace std;
int main()
{
string s,s1,s2;
while(getline(cin,s)){
int l=s.length()-1;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]==' '&&(i>0))
{
s1=s.substr(i+1,l-i);
// reverse(s1);
s2=s2+s1+' ';
l=i-1;
} if((i==0)&&(l>0)) s2=s2+s.substr(0,l+1); if((i==0)&&(l==0)) s2=s2+s[0]; } cout<<s2<<endl;
}
return 0;
}