题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
C语言,根据题意无脑模拟
#include <stdio.h>
int main() {
char ch[1005]; //输入
gets(ch);
char ans[1005][1005]; //输出
int hang = 0, lie = 0;
for (int i = 0; i < strlen(ch); i++) {
if (ch[i] == ' ') { //每次遇到空格,就是字符串加一
hang++;
lie = 0;
} else
ans[hang][lie++] = ch[i];
}
for (int i = hang; i >= 0; i--) { //倒着输出结果字符数组
printf("%s", ans[i]);
i & printf(" ");
}
printf("\n");
return 0;
}