#include <stdint.h> #include <stdio.h> #include <string.h> void swap(char* a, char* b) { char temp; if (a != b) { temp = *a; *a = *b; *b = temp; } else {} } int main() { char s[10001] = {}; uint32_t length = 0,i; uint32_t start,end; scanf("%[^\n]*c", s); length = strlen(s); // 替换非字母字符为空格 for (i=0; i<length; ++i) { if (s[i]<'A' || (s[i]>'Z'&&s[i]<'a') || s[i]>'z') { s[i] = ' '; } else {} } // 整体反转 for (start=0,end=length-1; start<end; ++start,--end) { swap(&s[start], &s[end]); } // 逐个单词倒排 for (i=0,start=0,end=0; i<length; ++i) { if ((s[i]==' ') || (i==length-1)) { if ((i==length-1) && (s[i]!=' ')) { end = i; } else { end = i-1; } for (; start<end; ++start,--end) { swap(&s[start], &s[end]); } start = i+1; } else {} } printf("%s", s); return 0; }