#include<iostream>
#include<string>
using namespace std;
void reverseString(string s);
string arr[100];
int k = 0;
int main(){
string str;
getline(cin, str);
if(str.find(" ") == str.npos){
cout<<str<<endl;
return 0;
}
else
reverseString(str);
for(int i = k - 1; i >= 0; i-- )
cout<<arr[i]<<" ";
cout<<endl;
return 0;
}
void reverseString(string s){
int position = 0;
while(1){
int tmposition = position;
//cout<<"tmposition = "<<tmposition<<endl;
position = s.find(" ",tmposition);
//cout<<"position = "<<position<<endl;
if(position == s.npos){
arr[k++] = s.substr(tmposition);
//cout<<"arr[k-1] = "<<arr[k-1]<<endl;
break;
}
arr[k++] = s.substr(tmposition, position - tmposition);
//cout<<"arr[k-1] = "<<arr[k-1]<<endl;
position++;
}
}
句子逆序
最新推荐文章于 2019-03-28 12:08:09 发布