题解 | #句子逆序#
句子逆序
http://www.nowcoder.com/practice/48b3cb4e3c694d9da5526e6255bb73c3
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main(){
char s[1001] = {0};
char s_temp[100] = {0};
gets(s);
for(int i=strlen(s)-1;i>=0;i--){
if(s[i] == ' '){
for(int j=strlen(s_temp)-1;j>=0;j--){
printf("%c",s_temp[j]);
}
printf(" ");
memset(s_temp,'\0',100);
}
else{
s_temp[strlen(s_temp)] = s[i];
}
}
for(int j=strlen(s_temp)-1;j>=0;j--){
printf("%c",s_temp[j]);
}
return 0;
}
查看3道真题和解析