题解 | #句子逆序#
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include <stdio.h> #include <string.h> int main() { int len; char *str = NULL; size_t is = 0; len = getline(&str, &is, stdin); char* p = str + len - 1; char* pEnd = p; char tmp[1000]; while (p != str) { if (*p == ' ') { memset(tmp, 0x00, 1000); strncpy(tmp, p + 1, pEnd - p - 1); printf("%s ", tmp); pEnd = p; } --p; } memset(tmp, 0x00, 1000); strncpy(tmp, p, pEnd - p); printf("%s", tmp); return 0; }