题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include<stdio.h>
#include<ctype.h>
#include<string.h>
int main()
{
char s[10000];
gets(s);
int len = strlen(s);
int p1 = len - 1, p2 = len;
while(p1 >= 0)
{
//不是字母的位置存起来,从是字母的输出到不是字母处,再查找下一个不是字母的位置存储。
while(p1 >= 0 && !isalpha(s[p1]))
p1--;
p2 = p1;
while(p1 >= 0 && isalpha(s[p1]))
p1--;
for(int i = p1 + 1; i <= p2; i++)
printf("%c", s[i]);
printf(" ");
}
return 0;
}

