题目:
题解:
void myResverse(char* s,int start,int end){while(start<end){char temp = s[start];s[start] = s[end];s[end] = temp;start++;end--;}
}
char* reverseWords(char* s) {int start = 0;int end = strlen(s)-1;myResverse(s,start,end);if(s[0]==' '){int i = 0;while(s[i]==' '){i++;}int j = 0;while(s[i]!='\0'){s[j] = s[i];i++;j++;}s[j] = '\0';}int check = 0;while(s[check]!='\0'){check++;}if(s[check-1]==' '){int o = check - 1;while(s[o]==' '){o--;}s[o+1] = '\0';}for(int k = 0;k<strlen(s);k++){if(s[k]==' '&&s[k+1]==' '){int i = k;while(s[i]==' '){i++;}int j = k+1;while(s[i]!='\0'){s[j] = s[i];i++;j++;}s[j] = '\0';}}int slow = 0;for(int u = 0;u<=strlen(s);u++){if(s[u]==' '||s[u]=='\0'){myResverse(s,slow,u-1);slow = u+1;}}return s;
}