【十二题解】 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include<stdio.h>
int is_right(char*a, int loc){
if((a[loc]>='a' && a[loc]<='z')|| (a[loc]>='A' && a[loc]<='Z')){
return 1;
}
else{
return -1;
}
}
int main(){
int sign = 1;
char charecter[10000]={0};
char*loc = charecter;
while(~scanf("%c", loc))loc++;
int lenth = (loc-charecter)/sizeof(char);
int i, j;
for(i=lenth-2; i>=0 ; i=j){
for(j=i; is_right(charecter, j)==sign; j--);
for(int x=j+1; x<=i; x++){
if(sign==1){
printf("%c", charecter[x]);
}
else{
printf(" ");
}
}
sign*=-1;
}
}