句子逆序-簡單題

#include<iostream>
using namespace std;
 
void reverse(char *start,char*end)
{
 while(start<end)
 {
  char t=*start;
  *(start++)=*end;
  *(end--)=t;
 }
}
 
void veversesentence(char *s)
{
 char *start=s;
 char *end =s;
 while(*end)
  end++;
 end--;
 reverse(start,end);
 start=end=s;
 while(*start)
 {
  if(*start==' ')
  {
   start++;
   end++;
  }
  else if(*end=='\0'||*end==' ')
  {
   reverse(start,--end);
   start=++end;
  }
  else
   end++;
 }
}
 
int main()
{
 char s[100]; 
 cin.getline(s,100);
 veversesentence(s);
 cout<<s;
 system("pause");
 return 0;
}
相關文章
相關標籤/搜索