int main() { char *str = "see you later"; int r = strlen(str); char * p = str; int a= 0; while(*str++!=‘\0‘) { if(*str == ‘ ‘) { a++; } } str-=(r+1); int arr[a]; int i,j; for(i =1,j=0;i<r;i++) { if(*str ==‘ ‘) { arr[j] = i; j++; } str++; } str-=(r-1); //puts(p+arr[1]); char arr2[r+1]; int k = 0; puts(p); while(*str!=‘\0‘) { if(*str == ‘ ‘) { arr2[k] = ‘\0‘; } else { arr2[k] = *str; } str++; k++; } arr2[k] = ‘\0‘; p = arr2; for(i = a-1;i>=0;i--) { puts(p+arr[i]); } puts(p); return 0; }
时间: 2024-12-05 22:35:27