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