1
1
1
1
1
1
#include <stdio.h>
#include <stdlib.h>
char* fzWords(char* s){
int len = strlen(s);
if(0==len||NULL==s){
return "";
}
int p = 0,q = len-1,r=0,i=0,j=0;
char *z = (char*)malloc(sizeof(char)*(len+1));
while(s[p] == ' ' && p <= q){
p++;
}
while(s[q] == ' '&& p <= q){
q--;
}
if(p > q){
return "";
}
r = p;
p = q;
while(1){
while(p >= 0 && s[p] != ' '){
p--;
}
for(i = p + 1;i <= q;i++){
z[j++] = s[i];
}
if(p + 1 == r){
break;
}
z[j++] = ' ';
while(s[p] == ' '){
p--;
}
q = p;
}
z[j] = '\0';
return z;
}
int main()
{
char s[1000];
gets(s);
printf(fzWords(s));
return 0;
}