#include<iostream>
using namespace std;
void fun(char *begin,char *end)
{
if(begin==NULL || end==NULL) return;
while(begin<end)
{
int temp = *begin;
*begin = *end;
*end = temp;
begin++;
end--;
}
}
void reverse(char *str)
{
if(str==NULL) return;
char *begin = str,*end = str;
while(*end !='\0')
{
end++;
}
end--;
fun(begin,end);
begin = end = str;
char *temp;
while(*begin !='\0')
{
if(*end ==' '||*end =='\0')
{ temp = end;
end--;
fun(begin,end);
temp++;
begin = end = temp;
}
end++;
}
}
void main()
{
char str[] ="I am a girl!";
int len = strlen(str);
reverse(str);
for(int i=0;i<len;i++)
{
cout<<str[i];
}
cout<<endl;
system("pause");
}
反转句子(自己写的)
最新推荐文章于 2019-02-22 13:13:12 发布