【十二题解】 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
有点晚了,直接暴力写法吧
#include<stdio.h>
int main(){
char word[1000];
scanf("%[^\n]\n", word);
int lenth = 0;
for (; word[lenth] != '\0'; lenth++);
int i = lenth -1;
for (; i>=0; i--){
if(word[i]== ' '){
for (int x =i+1; x<lenth; x++){
printf("%c", word[x]);
}
printf(" ");
lenth =i;
}
}
for (int x =0; x<lenth; x++){
printf("%c", word[x]);
}
return 0;
}