题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include <stdio.h> #include<string.h> int main() { char s[10000]={0}; gets(s); int len=strlen(s); for(int j=0;j<len;j++) { if((s[j]>='a'&&s[j]<='z')||(s[j]>='A'&&s[j]<='Z')||s[j]==' ') ; else s[j]=' '; } s[len]=' '; for(int i=len-1;i>=0;i--) { if(s[i]==' ') { int j=i+1; while(s[j]!=' ') { if((s[j]>='a'&&s[j]<='z')||(s[j]>='A'&&s[j]<='Z')||s[j]==' ') { printf("%c",s[j]); j++; } } printf(" "); } } int k=0; while(s[k]!=' ') { printf("%c",s[k]); k++; } return 0; }