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