#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAX_LEN 10 // Maximum length of the input string
int main() {
char input[MAX_LEN + 1]; // input string (plus one for the null character)
char output[MAX_LEN + 1]; // output string (plus one for the null character)
int len; // length of the input string
char order; // order of the sorting (either '+' or '-')
char case_; // case of the sorting (either '+' or '-')
printf("Enter a string of 9 characters or fewer (including both uppercase and lowercase letters): ");
scanf("%s", input);
len = strlen(input); // get the length of the input string
printf("Enter the order of the sorting (+ for ascending, - for descending): ");
scanf(" %c", &order); // note the space before %c to skip leading whitespace
printf("Enter the case of the sorting (+ for uppercase, - for lowercase): ");
scanf(" %c", &case_); // note the space before %c to skip leading whitespace
// Sort the input string based on the specified order and case
if (order == '+') {
if (case_ == '+') {
// Sort uppercase letters in ascending order
for (int i = 0, j = 0; i < len; i++) {
if (isupper(input[i])) {
output[j++] = input[i];
}
}
} else {
// Sort lowercase letters in ascending order
for (int i = 0, j = 0; i < len; i++) {
if (islower(input[i])) {
output[j++] = input[i];
}
}
}
} else {
if (case_ == '+') {
// Sort uppercase letters in descending order
for (int i = len - 1, j = 0; i >= 0; i--) {
if (isupper(input[i])) {
output[j++] = input[i];
}
}
} else {
// Sort lowercase letters in descending order
for (int i = len - 1, j = 0; i >= 0; i--) {
if (islower(input[i])) {
output[j++] = input[i];
}
}
}
}
// Add a null character to the end of the output string
output[len] = '\0';
printf("Output: %s\n", output);
return 0;
}