题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#include<stdio.h>
#include<stdlib.h>
int main()
{
char str[1001] = {0};
char temp[1001] = {0};
gets(str);
int len = strlen(str);
int k = 0;
int j = 0;
for(int i = len-1;i>=0;i--){
k = i;
if (str[i] == ' ') {
while (i<len-1 && str[i+1] != ' ') {
temp[j] = str[i+1];
j++;
i++;
}
temp[j] = ' ';
j++;
}
if (i == 0) {
while (str[i] != ' ') {
temp[j] = str[i];
j++;
i++;
}
}
i = k;
}
for(int i = 0;i<len;i++){
printf("%c", temp[i]);
}
return 0;
}