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