题解 | #倒置字符串#
倒置字符串
https://www.nowcoder.com/practice/ee5de2e7c45a46a090c1ced2fdc62355
#include <stdio.h> #include <string.h> void reverse(char* left, char* right ) { while (left < right) { char tmp = *left; *left = *right; *right = tmp; left++; right--; } } int main() { char str[101] = { 0 }; gets(str); int len = strlen(str) - 1; reverse(str, str+len); char* start = str; while (*start) { char* end = start; while (*end != ' ' && *end != '\0') { end++; } reverse(start, end - 1); if (*end == ' ') { start = end+1; } else { start = end; } } printf("%s\n", str); return 0; }