回复 5楼 lijilvly
之前题目看错
程序代码:
#include<stdio.h>
void reverse(char * str, int left, int right)
{
char tmp;
while(left<right)
{
tmp=str[left];
str[left]=str[right];
str[right]=tmp;
++left; --right;
}
}
int main()
{
char str[]="i love the girl";
int i=0, last_pos=0;
int is_in_word=0;
puts(str);
while(str[i]!='\0')
{
if(str[i]==' ')
{
if(is_in_word)
{
is_in_word=0;
reverse(str, last_pos, i-1);
}
}
else
{
if(!is_in_word)
{
is_in_word=1;
last_pos=i;
}
}
++i;
}
if(is_in_word)
{
is_in_word=0;
reverse(str, last_pos, i-1);
}
reverse(str, 0, i-1);
puts(str);
return 0;
}