#include "stdio.h" #include "math.h" #include "string.h" void main() { int i,j,k; char s[100]; char a[100]; int len; gets(s); for(i=0;s[i]!='\0';i++) { for(k=0;s[i]!=' ';k++,i++) { a[k]=s[i]; } a[k]='\0'; len=strlen(a); for(j=len-1;j>=0;j--) printf("%c",a[j]); if(s[i]=='\0') //if在后面判断,不然最外面for里i++会跳过空格 break; if(s[i]==' '&&s[i+1]!='\0') //不然结尾会多个空格 printf("%c",s[i]); strcpy(a,""); } } |
Double click to view unformatted code.