题解 | #句子逆序#
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include <stdio.h> int main() { char str[1000]; gets(str); int len = strlen(str); int count = 0; for (int i = len - 1; i >= 0; i--) { if (str[i] == ' ') { while (str[++i] != ' ' && str[i] != '\0') { printf("%c", str[i]); count++; } printf("%c", ' '); i = i - count - 1; count = 0; } if (i == 0) { while (str[i] != ' ') { printf("%c", str[i]); i++; } break; } } return 0; }