题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
C遍历代码:
#include <stdio.h> #include <string.h> int main() { char in[1000]; int s, e, index; fgets(in, sizeof(in), stdin); e = strlen(in) - 1; index = e - 1; for (; index>=0; index--){ if(in[index] == ' '){ s = index+1; for (; s<e; s++){ printf("%c", in[s]); } printf(" "); e = index; } } for(int i=0; i<e; i++) printf("%c", in[i]); return 0; }