#include <stdio.h> #include <stdlib.h> #include <string.h> #define max 30000 #define row 1001 #define col 1001 int is_upper(char a) { return((a >= 'A') && (a <= 'Z')); } int is_lower(char a) { return((a >= 'a') && (a <= 'z')); } char to_upper(char a) { if (is_lower(a)) { return a - ('a' - 'A'); } else { return a; } } char tolower(char a) { if (is_upper(a)) { return a + ('a' - 'A'); } else { return a; } } int char_cmp(char a, char b) { return(a - b); } int main() { char s[max]; char d[max]; int i = 0, j = 0, k = 0, m = 0, n = 0; char a, b, c; while (gets(s) != NULL) { m = strlen(s); strcpy(d, s); for (i = 0, j = 0; s[i] != '\0'; i++) { if (is_upper(s[i]) || is_lower(s[i]))//skip illegal character { s[j++] = s[i]; d[i] = -1; } } s[j] = 0; for (i = 0, m = 0; s[i] != '\0'; i++) { for (j = i + 1, k = i; s[j] != '\0'; j++) { if (is_upper(s[j])) { if (char_cmp(s[j], to_upper(s[k])) < 0) { k = j; } } else if (is_lower(s[j])) { if (char_cmp(s[j], tolower(s[k])) < 0) { k = j; } } else { } } if (k > i) { a = s[k]; for (j = k; j > i; j--) { s[j] = s[j - 1]; } s[i] = a; } } for (i = 0, j = 0; d[i] != '\0'; i++) { if (d[i] == -1) { d[i] = s[j++]; } } puts(d); } return 0; }