#include #include #include int main() { char buf[512]; int pos = 0, p, r, i; char c, t; srand((unsigned)time(NULL)); while ((c = getc(stdin)) != EOF) { if ( isupper(c) || islower(c)) { // if this is a letter buf[pos++] = c; // save the char } else { // reverse the word buf[pos] = 0; // end the word if (pos > 2) { // if length > 2 p = 1; t = buf[p]; // save the 2nd letter // reverse the word for 10 times randomly for (i = 0; i < 10; i++) { r = rand() % (pos-2) + 1; if (r >= 1 && r <= (pos-1)) { buf[p] = buf[r]; p = r; } } buf[p] = t; } pos = 0; printf("%s%c", buf, c); } } }