自己写的。C语言。题解 | #单词倒排#
单词倒排
https://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#include<stdio.h> int main() { char line[10002]; int i = 0, flag = 0, j; fgets(line, 10002, stdin); while (line[i] != 10 && line[i] != '\0') { i++; } i--; while (i >= 0) { if (line[i] >= 'a' && line[i] <= 'z') { flag++; } else if (line[i] >= 'A' && line[i] <= 'Z') { flag++; } else { if (flag > 0) { for (j = i + 1; j <= i + flag; j++) { printf("%c", line[j]); } printf(" "); flag = 0; } } if (i == 0 && flag > 0) { for (j = 0; j < flag; j++) { printf("%c", line[j]); } } i--; } }