题解 | #单词倒排#
单词倒排
http://www.nowcoder.com/practice/81544a4989df4109b33c2d65037c5836
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main() { char str[5000]; gets(str); int len = strlen(str); int flag = 0; int dp[5000] = {0}; for (int i = 0; i < len; i++) { if (((str[i] >= 'A') && (str[i] <= 'Z')) || ((str[i] >= 'a') && (str[i] <= 'z'))) { dp[i] = 1; } } int num = 0; for (int i = len - 1; i >= -1; i--) { if (dp[i] == 1) //是字母 { num++; if (i == 0) { for (int j = 0; j < num; j++) { printf("%c", str[i + j + 1]); } } } else { for (int j = 0; j < num; j++) { printf("%c",str[i+j+1]); } num = 0; printf(" "); } } return 0; }