题解 | #句子逆序#
句子逆序
https://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include <stdio.h> #include <string.h> void printWord(char* w) { char ch = *w; while(ch != ' ' && ch != 0) { if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { printf("%c",ch); } ch = *(++w); } } int main() { char str[1000] = {0}; char ch = 0; int len = 0; while('\n' != (ch = getchar())) { str[len++] = ch; } int wordEndp = len-1; for(int i = len-1; i >= 0; i--) { if(' ' == str[i] ) { printWord(&str[i+1]); printf(" "); } else if( 0 == i) printWord(&str[i]); } return 0; }#句子逆序#